execute_mongodb
Execute MongoDB commands using JSON syntax for find, aggregate, and more. Supports Extended JSON for BSON values like ObjectId and date.
Instructions
Execute a MongoDB command query. Use MongoDB command syntax, not Mongo shell JavaScript. Do not generate db.collection.find(...) or db.users.aggregate(...). Instead generate command JSON such as {"find":"users","filter":{"active":true},"limit":10}. For aggregate, include "cursor": {}, for example {"aggregate":"orders","pipeline":[{"$match":{"status":"paid"}}],"cursor":{}}. Use query when providing a string; it must be valid Extended JSON. Use $oid/$date Extended JSON for BSON values. In --readOnly mode, write/unknown commands are rejected, and aggregate with $out/$merge is treated as write.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | No | MongoDB command as an Extended JSON string. Prefer this when the AI is asked to provide a query string. Do not use Mongo shell JavaScript. Example: {"find":"users","filter":{"_id":{"$oid":"66f000000000000000000001"}},"limit":1}. | |
| command | No | MongoDB command document object. Example find: { find: 'users', filter: { active: true }, limit: 10 }. Example aggregate: { aggregate: 'orders', pipeline: [{ $match: { status: 'paid' } }], cursor: {} }. | |
| database | No | Database name. Defaults to the database from connect, or MongoDB driver's default. | |
| commandJson | No | Alias of query for Extended JSON command strings. Prefer query for new calls. | |
| connectionId | No | Connection id. Defaults to the latest connection. |