Esta página no está disponible en español. Se muestra la versión en inglés.

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 read access for reporting, and readWrite only on collections that workflows must change.
  • The connection string for that user: mongodb:// or mongodb+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

  1. 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 example mongodb+srv://reporting_user:your-password@cluster0.example.mongodb.net/?retryWrites=true&w=majority
    • mongodb_database: the default database, for example production

    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, include authSource in the connection string.

  2. 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.

  3. Smoke test with an MCP step

    In Workflow Studio, create a workflow with a single mcp step using tool_name mongodb_list_collections (no arguments) and run it. You should see the collections in your default database.

  4. Read a document (optional)

    Run mongodb_find_one with {"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 with mongodb_update_one.
  • Usage digest. Run mongodb_aggregate over 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 with mongodb_update_one.
  • Approval before deletes. Put a human approval step before mongodb_delete_many on a production collection.

Tools

Filters and documents are passed as JSON text (MongoDB Extended JSON) in parameters whose names end in _json.

Read

ToolWhat it does
mongodb_findFind documents matching a filter. Parameters: collection (required), filter_json, limit (default 20, max 200). Returns documents and count.
mongodb_find_oneFind one document. Parameters: collection (required), filter_json. Returns document.
mongodb_count_documentsCount documents. Parameters: collection (required), filter_json. Returns count.
mongodb_aggregateRun an aggregation pipeline. Parameters: collection and pipeline_json (required), limit (default 200, max 1000). Pipelines with $out or $merge are refused.
mongodb_list_databasesList database names on the cluster.
mongodb_list_collectionsList collection names. Parameter: database (defaults to your configured database).
mongodb_explainShow 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.

ToolWhat it does
mongodb_insert_oneInsert one document. Parameters: collection, document_json (both required).
mongodb_insert_manyInsert several documents. Parameters: collection, documents_json (a JSON array; both required).
mongodb_update_oneUpdate the first matching document. Parameters: collection, update_json (required, for example {"$set": {...}}), filter_json, upsert.
mongodb_update_manyUpdate all matching documents. Same parameters as mongodb_update_one.
mongodb_replace_oneReplace one document with a full new document. Parameters: collection, replacement_json (required), filter_json, upsert.
mongodb_delete_oneDelete the first matching document. Parameters: collection (required), filter_json.
mongodb_delete_manyDelete all matching documents. Parameters: collection (required), filter_json.
Advertencia

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

ToolWhat it does
mongodb_list_indexesList indexes on a collection. Parameter: collection (required).
mongodb_create_indexCreate an index. Parameters: collection and index_keys_json (required, for example {"email": 1}), index_name, unique. Writes to the database.
mongodb_drop_indexDrop 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):

KeyRequiredDefaultDescription
mongodb_urlYesnoneMongoDB connection URL (mongodb:// or mongodb+srv://).
mongodb_databaseYesnoneDefault database name for collection operations.
mongodb_request_timeout_secondsNo30Per-operation timeout in seconds.

Troubleshooting

IssueFix
missing required configuration: please set mongodb_url and mongodb_databaseThe connection lacks one of those keys, or the instance profile is not wired to it.
Timeout or connection refusedCheck the host in the connection string and that your IP access list or firewall allows AgentRuntime.
Authentication failedCheck 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-onlyRemove $out and $merge stages; use the write tools to store data.
Write rejectedCheck that the database user has readWrite on the collection.
Editar esta páginaagentruntime-io/agentruntime-docs