Skip to main content

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

FieldRequiredDescription
uriNoMongoDB connection URI (e.g. mongodb://user:pass@host:27017). Falls back to connection_string if not set, then to mongodb://localhost:27017.
connection_stringNoAlternate name for uri, used if uri is not set.
databaseNoDatabase 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

ParameterTypeRequiredDescription
collectionstringYesCollection name
filterstringNoJSON filter query (e.g. {"status":"active"})
limitnumberNoMaximum documents to return (default 20)
sortstringNoJSON 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

ParameterTypeRequiredDescription
collectionstringYesCollection name
documentstringYesJSON 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

ParameterTypeRequiredDescription
collectionstringYesCollection name
filterstringYesJSON filter to match documents
updatestringYesJSON update spec (e.g. {"$set":{"status":"done"}})
manybooleanNoUpdate 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

ParameterTypeRequiredDescription
collectionstringYesCollection name
filterstringYesJSON filter to match documents
manybooleanNoDelete 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.

Next