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
| Field | Required | Type | Description | Example |
|---|---|---|---|---|
hosts | Yes, in practice | Text | List of MongoDB hosts, comma-separated. | "mongo1:27017,mongo2:27017" |
database | Yes, in practice | Text | Database name. | "customers" |
username | No | Text | Username for authentication. | "app_user" |
password | No | Text | User's password. | "mypassword" |
authSource | No | Text | Database used to authenticate the user. Default value: "admin". | "admin" |
replicaSet | No | Text | Replica set name, if applicable. | "rs0" |
tls | No | Text ("true"/"false") | Enables an encrypted (TLS) connection. Default value: "false". | "true" |
srv | No | Text ("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
| Field | Required | Type | Description | Example |
|---|---|---|---|---|
collection | Yes | Text | Name of the MongoDB collection to use. | "customers" |
operation | Yes | Text: FIND, AGGREGATE, COUNT, INSERT, UPDATE, UPDATE_ALL, DELETE, DELETE_ALL, COLLECTION_STATS | Operation to run on the collection. | "FIND" |
variables | No | Text (JSON) | Map of values to replace :name-format placeholders inside query, filter, document, update, or aggregate. | {"customerId": 123} |
Fields by operation
| Operation | Fields | Description |
|---|---|---|
FIND | query (optional), limit (optional), skip (optional), sort (optional) | Finds documents matching the query filter. Response: list of documents in JSON. |
AGGREGATE | aggregate (optional) | Runs an aggregation pipeline. Response: list of results in JSON. |
COUNT | query (optional) | Counts documents matching the filter. Response: {"count": N}. |
INSERT | document (required) | Inserts a document into the collection. Response: inserted document (with _id). |
UPDATE | filter (required), update (required), multiUpdateEnabled (optional, default "true"), upsert (optional, default "false") | Updates documents matching filter. |
UPDATE_ALL | update (required), multiUpdateEnabled (optional, default "true") | Updates all documents in the collection. |
DELETE | filter (required) | Removes documents matching filter. |
DELETE_ALL | — | Removes all documents from the collection. |
COLLECTION_STATS | — | Returns 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 / Symptom | Likely Cause | How 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/update | The variables JSON is malformed (in that case it's just ignored, without stopping the flow). | Validate the JSON format of variables. |