Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

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

...

Snap Type

The MongoDB - Execute Snap is a Write type Snap. 

Prerequisites

...

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

  • MongoDB Execute This Snap supports only specific date-type formats because this Snap 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")

...

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

...

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.

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

...

  • 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: "Satish Mary test", body: "Execute snap for MongoDB snappack" } ]
    } )

  • Document updation into a collection

    Code Block
    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 

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

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

...

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

Insert excerpt
MongoDB Snap Pack
MongoDB Snap Pack
nopaneltrue

...

Related Content