Short Description |
Ports |
Metadata |
MongoDBExecute Attributes |
Details |
Examples |
See also |
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 | - | 0-1 | 0-2 | - |
Port type | Number | Required | Description | Metadata |
---|---|---|---|---|
Input | 0 | Input data records to be mapped to component attributes. | any | |
Output | 0 | Results | any | |
1 | Errors | any |
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.
Attribute | Req | Description | Possible values |
---|---|---|---|
Basic | |||
Connection | ID of the MongoDB connection to be used. | ||
Command | [ 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 " During the execution, each placeholder is replaced using simple string
substitution with the value of the respective input field, e.g.
the string " | @{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. |
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 | |
---|---|
MongoDBExecute internally uses the
|
Editing any of the Input, Output or Error mapping opens the Transform Editor.
The editor allows you to override selected attributes of the component with the values of the input fields.
Field Name | Attribute | Type | Possible values |
---|---|---|---|
command | Command | string |
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 Name | Type | Description |
---|---|---|
success | boolean | True if the execution has succeeded (can be false when Redirect error output is enabled). |
errorMessage | string | If the execution has failed, the field contains the error message (used when Redirect error output is enabled). |
stackTrace | string | If the execution has failed, the field contains the stack trace of the error (used when Redirect error output is enabled). |
stringResult | string | Conditional. If available, contains the return value of a successful execution serialized to a string. |
booleanResult | boolean | Conditional. Contains the return value of a successful execution, if it is a boolean. |
integerResult | integer | Conditional. If the return value of the execution is a number, contains its value as an integer. |
longResult | long | Conditional. If the return value of the execution is a number, contains its value as a long. |
numberResult | number | Conditional. If the return value of the execution is a number, contains its value as a floating point number. |
dateResult | date | Conditional. Contains the return value of a successful execution, if it is a date. |
stringListResult | string[] | Conditional. If the return value of the execution is iterable, contains the serialized elements as a list. |
mapResult | map[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. |
resultType | string | Conditional. Contains the canonical class name of the execution return value, if available. |
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 Name | Type | Description |
---|---|---|
success | boolean | Will always be set to false . |
errorMessage | string | The error message. |
stackTrace | string | The stack trace of the error. |
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()