MongoDBExecute

Available in Community Designer

Short Description
Ports
Metadata
MongoDBExecute Attributes
Details
Examples
See also

Short Description

MongoDBExecute executes JavaScript commands on the MongoDB™ database. [1]

Component Same input metadata Sorted inputs Inputs Outputs Each to all outputs Java CTL Auto-propagated metadata
MongoDBExecute-
no
0-10-2-
no
no
yes

Icon

Ports

Port typeNumberRequiredDescriptionMetadata
Input0
no
Input data records to be mapped to component attributes.any
Output0
no
Resultsany
1
no
Errorsany

Metadata

MongoDBExecute does not propagate metadata from left to right or from right to left.

This component has metadata templates available. The templates are described in Details. See general details on Metadata Templates.

MongoDBExecute Attributes

AttributeReqDescriptionPossible values
Basic
Connection
yes
ID of the MongoDB connection to be used. 
Commandyes  [ 1] JavaScript code to be executed on the MongoDB database. Mirrors the syntax used in the mongo shell.  
Input mapping[ 2]Defines mapping of input records to component attributes. 
Output mapping[ 2]Defines mapping of results to standard output port. 
Error mapping[ 2]Defines mapping of errors to error output port. 
Redirect error output If enabled, errors will be sent to the output port instead of the error port. false (default) | true
Advanced
Stop processing on fail  By default, a failure causes the component to skip all subsequent command executions and send the information about skipped executions to the error output port. This behaviour can be turned off by this attribute. true (default) | false
No lock  By default, MongoDB eval command takes a global write lock before evaluating the JavaScript function. As a result, the execution blocks all other read and write operations to the database while the operation runs. Set No lock to true to prevent the component from taking the global write lock before evaluating the JavaScript. No lock does not impact whether operations within the JavaScript code itself take a write lock. false (default) | true
Field pattern 

Specifies the format of placeholders that can be used within the Command attribute. The value of the attribute must contain "field" as a substring, e.g. "<field>", "#{field}", etc.

During the execution, each placeholder is replaced using simple string substitution with the value of the respective input field, e.g. the string "@{name}" will be replaced with the value of the input field called "name" (assuming the default format of the placeholders).

@{field} (default) | any string containing "field" as a substring

[ 1] The attribute is required, unless specified in the Input mapping.

[ 2]  Required if the corresponding edge is connected.

Details

Input mapping
Output mapping
Error mapping

MongoDBExecute executes JavaScript code against a MongoDB database connected using the Java driver. Input parameters can be received through the single input port and command results are sent to the first output port. Error information can be sent to the second output port.

The syntax of MongoDBExecute commands is similar to the mongo shell.

The component can be used to perform administrative operations that are not supported by the MongoDBReader or MongoDBWriter, e.g. to drop a collection, create an index, etc.

In general, you shouldn't use MongoDBExecute for reading or writing data to the database, if you can avoid it. Please use the MongoDBReader for reading from the database and the MongoDBWriter for inserting, updating or removing data.

[Warning]Warning

MongoDBExecute internally uses the eval command to execute the JavaScript code on the server, which has several limitations and implications:

  • By default, eval takes a global write lock before evaluating the JavaScript function. As a result, eval blocks all other read and write operations to the database while the operation runs. Set the No lock attribute to true to prevent the eval command from taking the global write lock before evaluating the JavaScript. No lock does not impact whether operations within the JavaScript code itself take a write lock.

  • Do not use MongoDBExecute for long running operations as the eval command blocks all other operations.

  • MongoDBExecute should not be used to retrieve large amounts of data, as there is no streaming support. In particular, transferring long arrays may lead to high memory requirements.

  • You can not use MongoDBExecute with sharded data. In general, you should avoid using eval in sharded cluster; nevertheless, it is possible to use it with non-sharded collections and databases stored in a sharded cluster.

  • With authentication enabled, eval will fail during the operation if you do not have the permission to perform a specified task.

    Furthermore, since version 2.4 you must have full admin access (readWriteAnyDatabase, userAdminAnyDatabase, dbAdminAnyDatabase and clusterAdmin privileges on the admin database) to run the eval command.

Editing any of the Input, Output or Error mapping opens the Transform Editor.

Input mapping

The editor allows you to override selected attributes of the component with the values of the input fields.

Field NameAttributeTypePossible values
commandCommandstring 

Output mapping

The editor allows you to map the results and the input data to the output port.

If output mapping is empty, fields of input record and result record are mapped to output by name.

Field NameTypeDescription
successbooleanTrue if the execution has succeeded (can be false when Redirect error output is enabled).
errorMessagestringIf the execution has failed, the field contains the error message (used when Redirect error output is enabled).
stackTracestringIf the execution has failed, the field contains the stack trace of the error (used when Redirect error output is enabled).
stringResultstringConditional. If available, contains the return value of a successful execution serialized to a string.
booleanResultbooleanConditional. Contains the return value of a successful execution, if it is a boolean.
integerResultintegerConditional. If the return value of the execution is a number, contains its value as an integer.
longResultlongConditional. If the return value of the execution is a number, contains its value as a long.
numberResultnumberConditional. If the return value of the execution is a number, contains its value as a floating point number.
dateResultdateConditional. Contains the return value of a successful execution, if it is a date.
stringListResultstring[]Conditional. If the return value of the execution is iterable, contains the serialized elements as a list.
mapResultmap[string, string]Conditional. Contains the return value of a successful execution, if it is a map. The values of the map are serialized to strings.
resultTypestringConditional. Contains the canonical class name of the execution return value, if available.

Error mapping

The editor allows you to map the errors and the input data to the error port.

If error mapping is empty, fields of input record and result record are mapped to output by name.

Field NameTypeDescription
successbooleanWill always be set to false.
errorMessagestringThe error message.
stackTracestringThe stack trace of the error.

Examples

The following command drops the collection named "orders":
db.orders.drop()
The following snippet creates indices on two fields of the collection named "orders" - "myField1" (ascending order of the keys) and "myField2" (descending order of the keys):
db.orders.createIndex({myField1 : 1});
db.orders.createIndex({myField2 : -1});
The following command returns the names of collections in the database as a list:
db.getCollectionNames()

See also

Common Properties of Components
Specific Attribute Types
Others Comparison
MongoDB connection


[1] MongoDB is a trademark of 10gen, Inc.