MongoDB connector
Find, aggregate, insert, update, and delete documents in MongoDB from AgentRuntime workflow steps.
En esta página
The mongodb connector lets workflow steps read and write documents in a MongoDB database you own, including MongoDB Atlas. It can look up documents, run aggregation pipelines, insert and update data, and manage indexes. Use it to keep a customer or event collection in sync with other tools, to build reports from your data, or to give an agent a way to look things up. For relational data see the Postgres connector.
Prerequisites
- A MongoDB deployment that AgentRuntime can reach over the network (self-hosted or MongoDB Atlas). If your cluster restricts access by IP address (Atlas calls this the IP access list), allow connections from AgentRuntime.
- A database user with a password. Give it
readaccess for reporting, andreadWriteonly on collections that workflows must change. - The connection string for that user:
mongodb://ormongodb+srv://. In Atlas, open your cluster and choose Connect to see the connection string for your cluster, then replace the placeholder password with the user's password. Atlas documents these steps in its own connection guide. - The name of the default database your workflows will use.
- Permission in your workspace to create connections and MCP instances (MCP write permission).
Connect in AgentRuntime
- Create a connection
Open Connections in the Console and click New custom connection. Optionally set a Display name, then under Credentials add these rows (Key and Value):
mongodb_url: your connection string, for examplemongodb+srv://reporting_user:your-password@cluster0.example.mongodb.net/?retryWrites=true&w=majoritymongodb_database: the default database, for exampleproduction
Click Save. The dialog also asks who can use the connection; choose the sharing option that fits your team. If your user was created in a database other than
admin, includeauthSourcein the connection string. - Add the mongodb MCP instance
Open MCP, click Add connectors, click the mongodb connector, then Add to workspace. Open Instance config, select your connection in the Connection picker, make sure the profile is active, and save.
- Smoke test with an MCP step
In Workflow Studio, create a workflow with a single
mcpstep usingtool_namemongodb_list_collections(no arguments) and run it. You should see the collections in your default database. - Read a document (optional)
Run
mongodb_find_onewith{"collection": "<your collection>"}to check you can read a real collection and see what its documents look like.
See Authentication for how connections are bound to MCP instances.
What you can build
- Contact enrichment. When a webhook arrives, look up the contact with
mongodb_find_one, merge in data from another tool, and save it withmongodb_update_one. - Usage digest. Run
mongodb_aggregateover an events collection on a schedule, let an LLM step summarize the result, and email it. - Ticket triage. Fetch open tickets with
mongodb_find, score them with an LLM, and set their status withmongodb_update_one. - Approval before deletes. Put a
humanapproval step beforemongodb_delete_manyon a production collection.
Tools
Filters and documents are passed as JSON text (MongoDB Extended JSON) in parameters whose names end in _json.
Read
| Tool | What it does |
|---|---|
mongodb_find | Find documents matching a filter. Parameters: collection (required), filter_json, limit (default 20, max 200). Returns documents and count. |
mongodb_find_one | Find one document. Parameters: collection (required), filter_json. Returns document. |
mongodb_count_documents | Count documents. Parameters: collection (required), filter_json. Returns count. |
mongodb_aggregate | Run an aggregation pipeline. Parameters: collection and pipeline_json (required), limit (default 200, max 1000). Pipelines with $out or $merge are refused. |
mongodb_list_databases | List database names on the cluster. |
mongodb_list_collections | List collection names. Parameter: database (defaults to your configured database). |
mongodb_explain | Show the query plan for a find or aggregate. Parameters: collection and operation (required), filter_json, pipeline_json, verbosity (default executionStats). |
Write
These tools change data.
| Tool | What it does |
|---|---|
mongodb_insert_one | Insert one document. Parameters: collection, document_json (both required). |
mongodb_insert_many | Insert several documents. Parameters: collection, documents_json (a JSON array; both required). |
mongodb_update_one | Update the first matching document. Parameters: collection, update_json (required, for example {"$set": {...}}), filter_json, upsert. |
mongodb_update_many | Update all matching documents. Same parameters as mongodb_update_one. |
mongodb_replace_one | Replace one document with a full new document. Parameters: collection, replacement_json (required), filter_json, upsert. |
mongodb_delete_one | Delete the first matching document. Parameters: collection (required), filter_json. |
mongodb_delete_many | Delete all matching documents. Parameters: collection (required), filter_json. |
An empty or missing filter_json matches every document. On mongodb_update_many and mongodb_delete_many always pass a filter unless you really mean the whole collection.
Indexes
| Tool | What it does |
|---|---|
mongodb_list_indexes | List indexes on a collection. Parameter: collection (required). |
mongodb_create_index | Create an index. Parameters: collection and index_keys_json (required, for example {"email": 1}), index_name, unique. Writes to the database. |
mongodb_drop_index | Drop an index by name. Parameters: collection, index_name (both required). Writes to the database. |
Example
Find recent signups for a welcome workflow:
{
"id": "recent-signups",
"type": "mcp",
"name": "Fetch recent signups",
"instance_id": "REPLACE_MONGODB_INSTANCE",
"tool_name": "mongodb_find",
"tool_args": {
"collection": "users",
"filter_json": "{\"created_at\": {\"$gte\": {\"$date\": \"2026-06-01T00:00:00Z\"}}}",
"limit": 50
},
"timeout_s": 30
}Use the documents in a later step with {{steps.recent-signups.result.documents}}.
Configuration
Connection keys (the connection's Key names):
| Key | Required | Default | Description |
|---|---|---|---|
mongodb_url | Yes | none | MongoDB connection URL (mongodb:// or mongodb+srv://). |
mongodb_database | Yes | none | Default database name for collection operations. |
mongodb_request_timeout_seconds | No | 30 | Per-operation timeout in seconds. |
Troubleshooting
| Issue | Fix |
|---|---|
missing required configuration: please set mongodb_url and mongodb_database | The connection lacks one of those keys, or the instance profile is not wired to it. |
| Timeout or connection refused | Check the host in the connection string and that your IP access list or firewall allows AgentRuntime. |
| Authentication failed | Check username and password, and add authSource to the connection string if the user lives in another database. |
invalid filter_json (or update_json, pipeline_json) | The value is not valid JSON. Escape quotes inside workflow JSON, and use Extended JSON forms such as {"$date": "..."} for dates. |
mongodb_aggregate is read-only | Remove $out and $merge stages; use the write tools to store data. |
| Write rejected | Check that the database user has readWrite on the collection. |