Skip to main content

MongoDB

1. Overview

The MongoDB component (mongodb) connects the flow to a MongoDB database, allowing you to find, insert, update, remove, and aggregate documents in a collection.

Use it when the flow needs to read or write data in a MongoDB database. Works only as an output action — it can't be used as an entry trigger (MongoDB doesn't "fire" the flow, it's queried by it).

2. Prerequisites

  • A MongoDB server accessible by the platform (host and port).
  • A username and password with permission to access the desired database (if authentication is enabled in MongoDB).
  • Network connectivity to the MongoDB host(s).

3. Authentication and Connection

FieldRequiredTypeDescriptionExample
hostsYes, in practiceTextList of MongoDB hosts, comma-separated."mongo1:27017,mongo2:27017"
databaseYes, in practiceTextDatabase name."customers"
usernameNoTextUsername for authentication."app_user"
passwordNoTextUser's password."mypassword"
authSourceNoTextDatabase used to authenticate the user. Default value: "admin"."admin"
replicaSetNoTextReplica set name, if applicable."rs0"
tlsNoText ("true"/"false")Enables an encrypted (TLS) connection. Default value: "false"."true"
srvNoText ("true"/"false")If true, uses the mongodb+srv:// connection scheme (DNS discovery), instead of the traditional scheme. Default value: "false"."true"

4. Configuration / Supported Operations

FieldRequiredTypeDescriptionExample
collectionYesTextName of the MongoDB collection to use."customers"
operationYesText: FIND, AGGREGATE, COUNT, INSERT, UPDATE, UPDATE_ALL, DELETE, DELETE_ALL, COLLECTION_STATSOperation to run on the collection."FIND"
variablesNoText (JSON)Map of values to replace :name-format placeholders inside query, filter, document, update, or aggregate.{"customerId": 123}

Fields by operation

OperationFieldsDescription
FINDquery (optional), limit (optional), skip (optional), sort (optional)Finds documents matching the query filter. Response: list of documents in JSON.
AGGREGATEaggregate (optional)Runs an aggregation pipeline. Response: list of results in JSON.
COUNTquery (optional)Counts documents matching the filter. Response: {"count": N}.
INSERTdocument (required)Inserts a document into the collection. Response: inserted document (with _id).
UPDATEfilter (required), update (required), multiUpdateEnabled (optional, default "true"), upsert (optional, default "false")Updates documents matching filter.
UPDATE_ALLupdate (required), multiUpdateEnabled (optional, default "true")Updates all documents in the collection.
DELETEfilter (required)Removes documents matching filter.
DELETE_ALLRemoves all documents from the collection.
COLLECTION_STATSReturns collection statistics.

5. Practical Examples

Simple example: find customers from a specific city.

Input:

{
"city": "São Paulo"
}

Component configuration:

{
"componentName": "mongodb",
"configurations": {
"collection": "customers",
"operation": "FIND",
"query": "{\"city\": \":city\"}",
"variables": "{\"city\": \"{$.body.city}\"}",
"limit": "10"
}
}

Response:

[
{ "_id": "64f1a2b3c4d5e6f7a8b9c0d1", "name": "Maria Silva", "city": "São Paulo" },
{ "_id": "64f1a2b3c4d5e6f7a8b9c0d2", "name": "John Smith", "city": "São Paulo" }
]

Advanced example: update a specific order's status, using filter/update with variables.

Input:

{
"orderId": "981",
"newStatus": "shipped"
}

Component configuration:

{
"componentName": "mongodb",
"configurations": {
"collection": "orders",
"operation": "UPDATE",
"filter": "{\"orderId\": \":id\"}",
"update": "{\"$set\": {\"status\": \":status\"}}",
"variables": "{\"id\": \"{$.body.orderId}\", \"status\": \"{$.body.newStatus}\"}",
"multiUpdateEnabled": "false"
}
}

Response:

{
"matchedCount": 1,
"modifiedCount": 1
}

6. Common Errors and Troubleshooting

Error / SymptomLikely CauseHow to Fix
"Connector IN Not supported for mongodb"Attempt to use MongoDB as an entry trigger.Use the component only as an output action in the flow.
"Collection empty."The collection field wasn't filled in.Fill in collection with the collection's name.
"Document empty"The INSERT operation without the document field.Fill in document with the JSON to insert.
"Filter empty"The UPDATE or DELETE operation without the filter field.Fill in filter with the search criteria.
"Update empty"The UPDATE/UPDATE_ALL operation without the update field.Fill in update with the update operator (e.g., $set).
"Operation [value] not found"The operation field doesn't match any supported operation.Use one of the valid values: FIND, AGGREGATE, COUNT, INSERT, UPDATE, UPDATE_ALL, DELETE, DELETE_ALL, COLLECTION_STATS.
Variables not replaced in query/filter/updateThe variables JSON is malformed (in that case it's just ignored, without stopping the flow).Validate the JSON format of variables.