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. It supports CRUD operations, index search, and aggregate functions.

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

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 field set.

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

  • 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.

note
  • 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, MongoDB automatically creates a new database.

  • 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, MongoDB 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.

note

The runCommand() method enables you to execute MongoDB commands that might 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.

The runCommand() method enables you to execute MongoDB commands that might 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 when the Snap fails to make a connection.

note

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

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.

Use the runCommand()

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

Examples:

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:

Step 1: 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

Step 2: 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

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

ex-retrieve-emp-data.png

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

mongo-db-execute-retrieve-emp-data-output.png


Related Content