MongoDB Execute
The MongoDB Execute step connects to a MongoDB cluster and executes Mongo shell-style commands.
Commands can:
Be statically defined.
Use placeholders that are substituted with values from incoming rows.
Be provided from a field in incoming rows.
Supported security providers
This step supports the following MongoDB server security providers:
SCRAM-SHA-1 / SCRAM-SHA-256
LDAP
Kerberos
X509
Step name
Step name specifies the unique name of the step on the canvas. You can change it.
Configure the step (tabs)
Configure connection tab
Use this tab to specify the connection string and command source.

Connection
String
MongoDB connection string URI. Both mongodb:// and mongodb+srv:// schemes are supported. This field supports variable substitution and can contain output from encr.bat / encr.sh. For URI construction, see MongoDB’s Connection String URI Format.
Test and Get DBs
Tests the connection string and lists databases you are authorized to access.
Database
Database to run commands against.
Command(s) source
You can provide commands in one of the following ways:
Script: run static commands.
Field: run commands stored in an incoming field.
Script option
Use the script area to enter one or more commands. Separate multiple commands with semicolons (;).

Execute for every row of input
Executes the command(s) once per incoming row. When selected, you can use placeholder substitution to incorporate values from the incoming row into the command.
Field option
Use this option when commands are provided in an incoming field.

Name
Name of the incoming field that contains one or more commands to execute.
Perform ? value substitution
Performs field-value substitution before the step runs.
Configure step tab
Use this tab to control step behavior.

Result field name
Adds a String field to the output stream containing the result information for each command executed. If multiple commands are executed, the step outputs a row of results for each command.
Command field name
Adds a String field containing the command associated with each result row. This helps downstream steps interpret results when multiple commands are executed. Leave blank to omit this field.
Stop on error
Stops the transformation when an error occurs. If not selected, errors are sent to the step’s error-handling stream.
Command reference
Commands generally follow MongoDB shell syntax. Arguments may be:
STRING(double or single quotes)BSON(less restrictive JSON)[ BSON, ... ]
Database commands
db.createCollection( STRING collectionName )
Creates a collection with the specified name. Example: db.createCollection("identities");
The String "true" when the collection is created. If the command fails, an error is raised.
db.listCollectionNames()
Lists the names of the collections in the selected database.
One output row per collection, with the result field containing the collection name.
db.listCollections()
Lists details of all collections in the selected database.
One output row per collection, with the result field containing a BSON document with collection details.
db.runCommand( BSON command )
Runs a command on the selected database. See db.runCommand for details. Example: db.runCommand( { find : "identities", projection : { superhero : 1, _id : 0 } } );
One output row, with the result field containing a BSON document of command results.
Collection commands
db.collection.aggregate( [BSON, ...] pipelineStages )
Runs an aggregation pipeline. Example: db.identities.aggregate( [ { $sort : { superhero : -1 } } ] ); See aggregation stages for details.
One output row for each BSON document produced.
db.collection.countDocuments()
Counts documents in a collection. Example: db.identities.countDocuments();
One output row with the count.
db.collection.countDocuments( BSON query )
Counts documents matching a query. Example: db.identities.countDocuments( { superhero : { $gt : "S" } } );
One output row with the count.
db.collection.countDocuments( BSON query, BSON options )
Counts documents matching a query and applies options: { limit: INTEGER, skip: INTEGER, maxTimeMS: LONG }. Example: db.identities.countDocuments( { superhero : { $gt : "S" } }, { limit : 1 } );
One output row with the count.
db.collection.deleteMany( BSON filter )
Deletes documents matching the filter. Example: db.identities.deleteMany( { superhero : { $gt : "Z" } } );
One output row with a BSON document that includes deletedCount and acknowledged.
db.collection.deleteOne( BSON filter )
Deletes at most one document matching the filter. Example: db.identities.deleteOne( { superhero : { $gt : "D" } } );
One output row with a BSON document that includes deletedCount and acknowledged.
db.collection.drop()
Drops a collection. Example: db.createCollection( "aliases" ); db.aliases.drop();
The String "true" when the collection is dropped.
db.collection.find()
Finds documents. Example: db.identities.find();
One output row per document found, with the result field containing the document as BSON.
db.collection.find( BSON query )
Finds documents matching a query. Example: db.identities.find( { superhero : { $gt : "S" } } );
One output row per document found, with the result field containing the document as BSON.
db.collection.insertMany( [BSON, ...] documents )
Inserts documents. Example: db.identities.insertMany( [ { superhero : "CodeMan" }, { superhero : "ETL Pro" } ] );
One output row with a BSON document that includes insertedIds and acknowledged.
db.collection.insertMany( [BSON, ...] documents, BSON options )
Inserts documents with options: { ordered: BOOLEAN }. Example: db.identities.insertMany( [ { superhero : "CodeMan" }, { superhero : "ETL Pro" } ], { ordered : true } );
One output row with a BSON document that includes insertedIds and acknowledged.
db.collection.insertOne( BSON document )
Inserts one document. Example: db.identities.insertOne( { superhero : "CodeMan" } );
One output row with a BSON document that includes insertedId and acknowledged.
db.collection.mapReduce( STRING map, STRING reduce )
Runs mapReduce with map and reduce functions provided as strings. Example: db.identities.mapReduce( "function() { emit( this.superhero, 1 ); }", "function( key, values ) { return values.length; }" );
Output rows containing BSON documents for mapReduce results.
db.collection.updateMany( BSON filter, BSON update )
Updates documents matching the filter. Example: db.identities.updateMany( { superhero : "CodeMan" }, { $set : { secret_identity: "John Doe" } } );
One output row with a BSON document that includes matchedCount, modifiedCount, and acknowledged.
db.collection.updateMany( BSON filter, BSON update, BSON options )
Updates documents using options: { upsert: BOOLEAN, arrayFilters: [ BSON, ...] }. Example: db.identities.updateMany( { superhero : "ETL Pro" }, { $set : { secret_identity: "Roger Smith" } }, { upsert : true } );
One output row with a BSON document that includes matchedCount, modifiedCount, upsertedId (when used), and acknowledged.
db.collection.updateOne( BSON filter, BSON update )
Updates at most one document matching the filter. Example: db.identities.updateOne( { superhero : "CodeMan" }, { $set : { secret_identity: "John Doe" } } );
One output row with a BSON document that includes matchedCount, modifiedCount, and acknowledged.
db.collection.updateOne( BSON filter, BSON update, BSON options )
Updates at most one document using options: { upsert: BOOLEAN, arrayFilters: [ BSON, ...] }. Example: db.identities.updateOne( { superhero : "ETL Pro" }, { $set : { secret_identity: "Roger Smith" } }, { upsert : true } );
One output row with a BSON document that includes matchedCount, modifiedCount, upsertedId (when used), and acknowledged.
Example
Example: Execute for every row of input
Incoming rows contain:
Roger
26
Peter
53
If the following command is in the script area:
db.people.insertOne( { first: "?{first_name}", age: ?{age} } );
The step evaluates and executes these commands:
db.people.insertOne( { first: "Roger", age: 26 } );
db.people.insertOne( { first: "Peter", age: 53 } );
Metadata injection support
All fields of this step support metadata injection. You can use it with ETL metadata injection to pass metadata to your transformation at runtime.
Last updated
Was this helpful?

