$customHeader
Skip to end of banner
Go to start of banner

MongoDB - Execute

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 19 Next »

In this article

Overview

You can use this Snap to execute all Data Manipulation Language (DML) and Data Definition Language (DDL) commands on the MongoDB database.

mongo-db-execute-overview.png

Snap Type

The MongoDB - Execute Snap is a Write type Snap. 

Prerequisites

None.

Support for Ultra Pipelines

Works in Ultra Pipelines

Limitations

  • MongoDB driver has limited support for inline or multiline comments in a command.

  • This Snap supports only specific date-type formats because it uses a Mongo template that supports only JSON format. A few of the supported date-type formats are:

    • { "$date": "2020-09-01T00:00:00Z" }

    • ISODate("2020-01-15T00:00:00Z")

Known Issues

None.

Supported Versions

The Mongo-DB Execute Snap is tested against v4.2.24.

Snap Views

Type

Format

Number of Views

Examples of Upstream and Downstream Snaps

Description

Input 

Document

  • Min: 0

  • Max: 1

  • Mapper

  • JSON Generator

  • JSON Formatter

Requires the command to be executed on the specified database.

Output

Document

  • Min: 0

  • Max: 1

  • Mapper

  • Copy

  • File Writer

The original document that was used to create the statement will be output with the status of the statement executed.

Error

Error handling is a generic way to handle errors without losing data or failing the Snap execution. You can handle the errors that the Snap might encounter when running the Pipeline by choosing one of the following options from the When errors occur list under the Views tab:

  • Stop Pipeline Execution: Stops the current Pipeline execution if the Snap encounters an error.

  • Discard Error Data and Continue: Ignores the error, discards that record, and continues with the remaining records.

  • Route Error Data to Error View: Routes the error data to an error view without stopping the Snap execution.

Learn more about Error handling in Pipelines.

Snap Settings

  • Asterisk ( * ): Indicates a mandatory field.

  • Suggestion icon ((blue star)): Indicates a list that is dynamically populated based on the configuration.

  • Expression icon ((blue star) ): Indicates the value is an expression (if enabled) or a static value (if disabled). Learn more about Using Expressions in SnapLogic.

  • Add icon ( (blue star) ): Indicates that you can add fields in the fieldset.

  • Remove icon ( (blue star)): Indicates that you can remove fields from the fieldset.

  • Upload icon ((blue star) ): Indicates that you can upload files.

Field Name

Field Type

Description

Label*

Default ValueMongoDB - Execute
ExampleExecute Lookup for Customers

String

Enter a unique name for the Snap. You can modify this to be more specific, especially if you have more than one of the same Snap in your pipeline.

Database name

Default Value: N/A
Example: mydatabase

String/Suggestion

Specify the database name where the query is executed.

  • If you do not specify a database name, the database configured in the MongoDB Account is used for Snap processing.

  • If you provide a database name that is not available in the dropdown list, Mongo automatically creates a new database.

Command*

Default Value: N/A
Example: { find: "collectionName"}

String/Expression

Specify the MongoDB command to execute on the MongoDB instance using the runCommand() operation. Learn more.

runCommand() method enables you to execute MongoDB commands that may not be readily available through the standard MongoDB query language, such as CRUD operations. The syntax of the runCommand() method in MongoDB is as follows:

db.runCommand( { <command>: <value> } )

  • <command>: The command or operation you want to execute.

  • <value>: Optional. Additional parameters or options specific to the command being executed.

Number of retries

Default Value0
Example: 4

Integer

Specify the number of retry attempts to make when the Snap fails to make a connection.

When the retry connection fails, an error message is written to the Error View.

Retry interval (seconds)

Default Value: 1
Example: 5

Integer

Specify the time interval between two retry requests.

Snap Execution

Default ValueExecute only
Example: Validate & Execute

Dropdown list

Select one of the following three modes in which the Snap executes:

  • Validate & Execute: Performs limited execution of the Snap, and generates a data preview during Pipeline validation. Subsequently, performs full execution of the Snap (unlimited records) during Pipeline runtime.

  • Execute only: Performs full execution of the Snap during Pipeline execution without generating preview data.

  • Disabled: Disables the Snap and all Snaps that are downstream from it.

Usage of runCommand()

You can use the runCommand() to perform the following:

  • Administrative tasks: You can check Server status, do database profiling, replication-related operations, user management, and more.

  • Access internal commands: You can access and execute the internal commands.

  • Diagnostic Commands: You can execute diagnostic commands to gather information about the database, collections, indexes, or server status.

Examples:

  • Checking server status
    db.runCommand({ serverStatus: 1 })

  • Listing databases:
    db.runCommand({ listDatabases: 1 })

  • Checking the current operation in progress
    db.runCommand({ currentOp: 1 })

  • Document insertion into a collection
    db.runCommand( {
    insert: "Test1",
    documents: [ { _id: 7, title: "Mary test", body: "Execute snap for MongoDB snappack" } ]
    } )

  • Document updation into a collection

    db.runCommand({
          update: "Test1",
          updates: [
             {
               q: { title: "abc123" }, 
               u: { $set: { body: "Toy Story" },  $inc: { points: 1 } }
             }
          ],
          ordered: false,
          writeConcern: { w: "majority", wtimeout: 5000 }
       })
  • Document deletion from collection 

    db.runCommand({
          delete: "Test1",
          deletes: [
             {
               q: { title: "Mary test" }, 
                limit: 1
             }
          ],
          ordered: false,
          writeConcern: { w: "majority", wtimeout: 5000 }
       }) 
  • Creating indexes for a collection

    db.runCommand(
       {
         createIndexes: "collectionName",
         indexes: [
             {
                 key: {
                     field1: 1,
                     field2: -1
                 },
                 name: "indexName",
                 unique: true
             },
             { ... },
             { ... }
         ],
         writeConcern: { w: "majority" },
         commitQuorum: 1,
         comment: "Optional comment"
       }
     )

Example

This example demonstrates how to use the common (Create, Insert, and Find) commands in MongoDB.

ex-pipeline-overview.png

Download this pipeline.

Configure the pipeline with three MongoDB Execute Snaps to perform the create, insert, and find operations. Each Snap in this pipeline performs the following operations:

  • Create employee details collection (collection indicates a table in MongoDB)

  • Insert the employee data into the collection

  • Retrieve the employee data

Create: Configure the Execute Snap with the create command to create a collection named employees_data with id, name, and salary fields.

ex-mongodb-exe-create-coll-config.png

Insert: Configure the Execute Snap with the insert command to insert three records of employees (id:1, id:2, id:3) with their salary details.

ex-insert-emp-data.png

Find: Configure the Execute Snap with the findcommand to retrieve the employee details.

ex-retrieve-emp-data.pngmongo-db-execute-retrieve-emp-data-output.png

On validation, you can view the inserted records of the employees in the employee_data collection.

Snap Pack History

 Click to view/expand
Release Snap Pack VersionDateType  Updates
May 2024main26341 Stable
  • Enhanced the MongoDB Update Snap with the Array Filters field, which enables you to use array filters in the update operation. Additionally, the Update Query field is modified into a text box for visibility and usability of input queries.
  • Upgraded Spring dependencies to the latest supported Java 11 version for MongoDB Snap Pack.

February 2024436patches26244 Latest

Added the following Snap to the MongoDB Snap Pack:

  • MongoDB - Atlas Vector Search: Performs advanced vector-based queries, such as Similarity searches, Approximate Nearest Neighbor (ANN) queries, and Range queries on vector data stored in MongoDB Atlas.

February 2024436patches25893 Latest

Added MongoDB Execute Snap to the MongoDB Snap Pack.

February 2024main25112 StableUpdated and certified against the current SnapLogic Platform release.
November 2023main23721 StableUpdated and certified against the current SnapLogic Platform release.

August 2023

main22460

 


Stable

Updated and certified against the current SnapLogic Platform release.

May 2023

main21015 

Stable

Upgraded with the latest SnapLogic Platform release.

February 2023main19844 StableUpgraded with the latest SnapLogic Platform release.
November 2022main18944 StableUpgraded with the latest SnapLogic Platform release.
September 2022430patches18223 Latest

The MongoDB Update Snap in a low-latency feed Ultra Pipeline now correctly acknowledges the requests.

August 2022430patches17472 Latest

The MongoDB Account with Encryption type set to TLS/SSL does not fail with the "URL cannot be null" error.

August 2022main17386 StableUpgraded with the latest SnapLogic Platform release.
4.29Patches429patches15807 Latest

Updated the expected output for the MongoDB - Update Snap that is changed because of the upgrade of Spring Core framework version.

4.29

main15993

  

Stable

Upgraded with the latest SnapLogic Platform release.

4.28main14627 StableUpgraded with the latest SnapLogic Platform release.

4.27

main12833

 

Stable

Upgraded with the latest SnapLogic Platform release.
4.26main11181 StableUpgraded with the latest SnapLogic Platform release.
4.25main9554
 
StableUpgraded with the latest SnapLogic Platform release.
4.24main8556
Stable

Fixed an issue in the MongoDB accounts to connect to Atlas Free Tier and Shared Cluster database using the Use cursor timeout checkbox in the MongoDB cursor properties. If selected, this option enables the server to close a cursor automatically after a period of inactivity. For the existing accounts that does not have this field, the value for this checkbox returns false, which is backward compatible.

4.23main7430
 
StableUpgraded with the latest SnapLogic Platform release.
4.22main6403
 
StableUpgraded with the latest SnapLogic Platform release.

4.21 Patch

421patches6272 Latest

Fixes the issue where Snowflake SCD2 Snap generates two output documents despite no changes to Cause-historization fields with DATE, TIME and TIMESTAMP Snowflake data types, and with Ignore unchanged rows field selected.

4.21 Patch

421patches6144 Latest

Fixes the following issues with DB Snaps:

  • The connection thread waits indefinitely causing the subsequent connection requests to become unresponsive.
  • Connection leaks occur during Pipeline execution.
4.21 PatchMULTIPLE8841 Latest

Fixes the connection issue in Database Snaps by detecting and closing open connections after the Snap execution ends. 

4.21snapsmrc542

 

StableUpgraded with the latest SnapLogic Platform release.
4.20snapsmrc535
 
StableUpgraded with the latest SnapLogic Platform release.
4.19snaprsmrc528
 
StableUpgraded with the latest SnapLogic Platform release.
4.18snapsmrc523
 
Stable
  • Added the following fields to the Mongo DB Find Snap: Projection Condition, Sort ConditionOffset, Limit, and Group result.
  • Added a new Snap, MongoDB Group, which enables you to group input documents by a specified expression, and output to the next stage, one document for each distinct grouping.
  • Added a new field to the Mongo DB Update Snap, Update operation and Exclude list, which enable you to update operations and exclude a list of JSON properties before sending the updated documents to MongoDB.
4.17ALL7402
 
Latest

Pushed automatic rebuild of the latest version of each Snap Pack to SnapLogic UAT and Elastic servers.

4.17 Patch db/mongo7331 Latest
  • Fixed an issue with the MongoDB - Update Snap wherein the Snap converts all non-updated integer and float data types to string data type.
  • Fixed a Null Pointer Exception for old MongoDB accounts that did not have driver jars.
4.17snapsmrc515
 
Latest

Added the Snap Execution field to all Standard-mode Snaps. In some Snaps, this field replaces the existing Execute during preview check box.

4.16snapsmrc508
 
StableUpgraded with the latest SnapLogic Platform release.
4.15 Patch db/mongo6783 Latest

Fixed connection timeout issue with MongoDB.

4.15 Patch db/mongo6465 Latest

Fixed an issue wherein REST calls to Ultra tasks returned an error message.

4.15snapsmrc500
 
StableUpgraded with the latest SnapLogic Platform release.
4.14 Patch db/mongo5666 Latest

Fixed the Update, Delete, and Find Snaps to populate input view schema for a given table, similar to the Insert Snap.

4.14snapsmrc490
 
StableUpgraded with the latest SnapLogic Platform release.
4.13 Patchmongo5537 Latest

Fixed the Update, Delete, and Find Snaps to populate input view schema for a given table, similar to the Insert Snap.

4.13

snapsmrc486

 
StableUpgraded with the latest SnapLogic Platform release.
4.12

snapsmrc480

 
Stable

Added the SSl certification properties to all the MongoDB Accounts to ensure the validation of the certificate.

4.11snapsmrc465
 
StableUpgraded with the latest SnapLogic Platform release.
4.10 Patchmongo3978 Latest

Resolved an issue where the NumberFormatException was not handled properly for some of the valid Number Types like "NaN"/ "+Infinity"/ "-Infinity".


4.10

snapsmrc414

 
StableUpgraded with the latest SnapLogic Platform release.
4.9.0 Patchmongodb3259 Latest
  • Addressed an issue in MongoDB Update where Upsert Date failed with "Can't find a codec for class org.joda.time".
  • MongoDB Insert Snap - Collectio name expression evaluate fixed.
4.9snapsmrc405
 
Stable
  • Query Condition property is now an expression that evaluates to an object or JSON string.
  • Updated the Snap with Database name property to support the users defined in an authentication database.
4.8.0 Patchmongodb2735 Latest

Added SSL encryption type to all MongoDB accounts and Replica set Accounts and removed the MongoDB SSL account.

4.8

snapsmrc398

 
Stable
  • The MongoDB Delete Snap and MongoDB Update Snap were introduced in this release.
  • Enhanced the MongoDB Snap account with SSL Account type.
  • Updated the Batch Size property in MongoDB Find with the default value of 0.
  • Enhanced the MongoDB Find Snap documentation with an example.
  • Info tab added to accounts.
  • Database accounts now invalidate connection pools if account properties are modified and login attempts fail.
4.7 Patchmongo2375 Latest
  • Update the MongoDB java driver to 3.0.4; Add exception handling to each record processing.
  • MongoDB SSL Account removed and replaced with the new configuration for all the Accounts (Encryption type Property).
4.7 Patchmongo2338 Latest

Add an account for MongoDB SSL connection without certificates validation

4.7 Patchmongo2200 Latest

Fixed an issue for database Select Snaps regarding Limit rows not supporting an empty string from a pipeline parameter.

4.7

snapsmrc382

 
Stable

Updated the Snap account with the LDAP Authentication type.

4.6snapsmrc362
 
Stable

Resolved an issue in MongoDB Insert Snap that processed and inserted all numeric fields as strings.

4.5.1

snapsmrc344

 
Stable
  • Resolved and issue with MongoDB Insert with an empty input view failed.
  • Resolved an issue with MongoDB Insert that changed a numeric type field in MongoDB as String.
  • Resolved an issue that caused Snap execution failures when accessing MongoDB using a Replica Set account.
4.3.2
 Stable

Resolved an issue with MongoDB Find returning nothing when nothing was found.


4.3

Stable
  • Resolved an issue with an incorrect resolution displaying during account validation if the username was blank.
  • Resolved an issue in the MongoDB Find Snap with nested arrays.
  • Resolved an issue in MongoDB Find with data not being usable be other Snaps.
4.2.2

Stable
  • Username and Password are no longer required fields when creating a MongoDB account because it is possible to configure an instance where that information is not required.
  • MongoDB Aaccount now supports Mongo Java Driver 3.0.2.
  • MongoDB Find
    • Resolved an issue with MongoDB Find not properly supporting the expression language.
    • Resolved an issue with MongoDB Find returning "Current context not an ARRAY but OBJECT" for a deep nested ObjectId object.
    • Resolved an issue with MongoDB Find when data had built-in datatype.
    • Resolved a null pointer exception in MongoDB Find.
    • Resolved an issue with MongoDB Find not routing failed documents to the error view.
  • Resolved an issue with MongoDB error handling when maximum number of documents reached.
  • Improved the error message presented when MongoDB database could not reach the JCC.
4.2.1

Stable
  • MongoDB - Find: Resolved Error- Failure: java.util.HashMap cannot be cast to java.lang.String when in query condition passes without single quotes.
  • MongoDB - Find: Resolved failure with Query Using Operators.
  • Resolved MongoDB driver and account do not support current version of MongoDB.
  • Resolved a failure MongoDB Insert with custom _id.


Related Content

  • No labels