Mongo DB makes operations in a Mongo database connection, returning only one JSON object.
     

IMPORTANT: mind the memory consumption for big datasets.


Take a look at the configuration parameters of the component:

  • Account: account to be used by the component.

  • Operation: operation to be executed (FIND, AGGREGATE, DELETE ONE, DELETE MANY, INSERT ONE, INSERT MANY, UPDATE ONE, UPDATE MANY and REPLACE ONE).

  • Connection String: connection of the string.

  • Database Name: name of the database.

  • Collection Name: name of the collection.

  • Query: Mongo specification to be queued. For example:
    { _id: ObjectId( {{ message.$.id }} ) }

  • Limit: specification of the maximum number of objects that can be returned.

  • Skip: number of objects to be skipped before returning to the query.

  • Sort: specification of the parameter to be sorted by the field.

  • Fail On Error: if the option is enabled, the execution of the pipeline with error will be interrupted; otherwise, the pipeline execution proceeds, but the result will show a false value for the “success” property.

       

You can:

- use a fixed JSON:

document = "{\"data\": [{\"object\": 1}, {\"object\": 2}]}"
    

- get some JSON of the message, that will search the 'data' object of the message:

document = "{{ message.$.data }}
    

- combine both examples:

document = "{\"data\": [{\"object\": {{ message.$.id1 }}}, {\"object\": {{ message.$.id2 }}}]}"]
    

If MongoDB needs some authentication, you must create an account (BASIC type) and use it in the component. 

To convert Douuble Braces, we use JSON Path specifications. Click here to know more.  
   

Mongo DB in Action

Operation FIND

Config

{
"operation": "FIND",
"databaseName": "test",
"collectionName": "model",
"url": "mongodb://localhost:27017",
"query": "{_id: ObjectId({{ message.$.parameters.id }})}",
"failOnError": false
}

Input

{
"parameters": {
"id": "5c87c7af06c3af7dbedc7bb3"
}
}

Output

{
"data": [...some data...],
"rowCount": 10,
"updateCount": 0
}

Operation REPLACE ONE

Config

{
"operation": "REPLACE_ONE",
"databaseName": "test",
"collectionName": "model",
"document": "{\"data\": [{\"object\": 1}, {\"object\": 2}]}",
"url": "mongodb://localhost:27017",
"query": "{_id: ObjectId({{ message.$.parameters.id }})}",
"failOnError": false
}

Input

{
"parameters": {
"id": "5c87c7af06c3af7dbedc7bb3"
}
}

Output

{
"data": {},
"rowCount": 0,
"updateCount": 1
}

Operation UPDATE

Config

{
"operation": "UPDATE",
"databaseName": "test",
"collectionName": "model",
"document": "{\"$set\": {\"data\": [{\"object\": 1}, {\"object\": 2}]}}",
"url": "mongodb://localhost:27017",
"query": "{_id: ObjectId({{ message.$.parameters.id }})}",
"failOnError": false
}

Input

{
"parameters": {
"id": "5c87c7af06c3af7dbedc7bb3"
}
}

Output

{
"data": {},
"rowCount": 0,
"updateCount": 1
}

Operation UPDATE MANY

Config

{
"operation": "UPDATE_MANY",
"databaseName": "test",
"collectionName": "model",
"document": "{\"$set\": {\"data\": [{\"object\": 1}, {\"object\": 2}]}}",
"url": "mongodb://localhost:27017",
"query": "{name: ObjectId({{ message.$.parameters.name }})}",
"failOnError": false
}

Input

{
"parameters": {
"name": "NAME"
}
}

Output

{
"data": {},
"rowCount": 0,
"updateCount": 1
}

Operation DELETE

Config

{
"operation": "DELETE",
"databaseName": "test",
"collectionName": "model",
"url": "mongodb://localhost:27017",
"query": "{_id: ObjectId({{ message.$.parameters.id }})}",
"failOnError": false
}

Input

{
"parameters": {
"id": "5c87c7af06c3af7dbedc7bb3"
}
}

Output

{
"data": {},
"rowCount": 10,
"updateCount": 0
}

Operation DELETE MANY

Config

{
"operation": "DELETE_MANY",
"databaseName": "test",
"collectionName": "model",
"url": "mongodb://localhost:27017",
"query": "{name: {{ message.$.data.name }}}",
"failOnError": false
}

Input

{
"data": {
"name": "NAME"
}
}

Output

{
"data": {},
"rowCount": 10,
"updateCount": 0
}

Operation INSERT

Config

{
"operation": "INSERT",
"databaseName": "test",
"collectionName": "model",
"document": "{\"data\": {{ message.$.body }}}",
"url": "mongodb://localhost:27017",
"failOnError": false
}

Input

{
"parameters": {
"id": "5c87c7af06c3af7dbedc7bb3"
},
"body": [
{"a": 1},
{"a": 2}
]
}

Output

{
"data": {},
"rowCount": 0,
"updateCount": 1
}

Operation INSERT MANY

Config

{
"operation": "INSERT_MANY",
"databaseName": "test",
"collectionName": "model",
"document": "{{ message.$.body }}",
"url": "mongodb://localhost:27017",
"failOnError": false
}

Input

{
"parameters": {
"id": "5c87c7af06c3af7dbedc7bb3"
},
"body": [
{"a": 1},
{"a": 2}
]
}


Output

{
"data": {},
"rowCount": 0,
"updateCount": 1
}

Operation AGGREGATE

Config

{
"operation": "AGGREGATE",
"databaseName": "test",
"collectionName": "model",
"url": "mongodb://localhost:27017",
"query": "[{\"$match\":{\"zip\":\"90210\"}},{\"$group\":{\"_id\":null,\"count\":{\"$sum\":1}}}]",
"failOnError": false
}

Input

{
"parameters": {
"id": "5c87c7af06c3af7dbedc7bb3"
}
}

Output

{
"data": [...some data...],
"rowCount": 10,
"updateCount": 0
}


Mongo DB supports static Double Braces in the following parameters that were previously specified:

  • operation

  • url

To read our article about Double Braces, click here.

Did this answer your question?