MongoDB
Connects to a MongoDB database for document CRUD operations. An agent can query, insert, update, delete documents, and list collections.
Add to an agent node's tools array with _node_type: "tool-mongodb". See Connector Reference — How connectors are used.
Authentication
| Field | Required | Description |
|---|---|---|
uri | No | MongoDB connection URI (e.g. mongodb://user:pass@host:27017). Falls back to connection_string if not set, then to mongodb://localhost:27017. |
connection_string | No | Alternate name for uri, used if uri is not set. |
database | No | Database name to operate on. Defaults to test. |
{
"name": "mongodb",
"_node_type": "tool-mongodb",
"uri": "{{ secret.MONGODB_URI }}",
"database": "production"
}
Tools
mongodb_find
Query documents from a MongoDB collection.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
collection | string | Yes | Collection name |
filter | string | No | JSON filter query (e.g. {"status":"active"}) |
limit | number | No | Maximum documents to return (default 20) |
sort | string | No | JSON sort spec (e.g. {"created_at":-1}) |
Returns: A line stating the document count followed by the matching documents as indented JSON.
mongodb_insert
Insert a document into a MongoDB collection.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
collection | string | Yes | Collection name |
document | string | Yes | JSON document to insert |
Returns: A confirmation message containing the inserted document's ID.
mongodb_update
Update one or many documents in a MongoDB collection.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
collection | string | Yes | Collection name |
filter | string | Yes | JSON filter to match documents |
update | string | Yes | JSON update spec (e.g. {"$set":{"status":"done"}}) |
many | boolean | No | Update all matching documents (default false) |
Returns: A line in the form matched=<N> modified=<N>.
mongodb_delete
Delete one or many documents from a MongoDB collection.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
collection | string | Yes | Collection name |
filter | string | Yes | JSON filter to match documents |
many | boolean | No | Delete all matching documents (default false) |
Returns: A line in the form deleted=<N>.
mongodb_list_collections
List all collections in the MongoDB database.
No parameters.
Returns: A newline-separated list of collection names.