GuidesMongoDB
An AI agent for MongoDB that writes queries, not pipelines.
On MongoDB the agent writes the same queries it writes for Postgres. The engine turns each one into an aggregation pipeline: $match for filters, $lookup for relationships, $project for the fields asked for. One query language covers your documents and your SQL databases.
The short version
What you get on MongoDB.
- Pipelines written by the engine. Filters, ordering, limits, relationships and embedded arrays compile into one aggregation pipeline. The model never builds a pipeline by hand.
- Joins across collections. A nested selection becomes a
$lookupwith its own pipeline. An array of ids joins with$in. - One language across databases. A question that spans MongoDB and Postgres is written once; the engine runs each part on its own database.
- Rules from the caller. Row filters from the signed-in person’s role are added to the
$matchstage.
Connect
Connection, database and relationships.
curl -fsSL https://deeporg.io/install.sh | bash# config/dev.yml
sources:
- name: docs
kind: database
type: mongodb
default: true
# mongodb+srv://user:pass@cluster.example.net
connection_string: ${MONGODB_URI}
dbname: app # required: the database to read
read_only: true # start read-onlyName the database in dbname; the one in the URI is not used. MongoDB has no foreign keys, so tell the engine how collections relate:
tables:
- name: orders
columns:
- name: customer_id
foreign_key: customers.idThe agent then follows orders → customer as it would on any SQL database. Fields are addressed as id; the engine maps them to _id.
deeporg serveYour AI client
Add it to Claude Code or Codex.
claude mcp add deeporg -- deeporg mcp --path /absolute/path/to/config
codex mcp add deeporg -- deeporg mcp --path /absolute/path/to/configYour client’s model does the reasoning. With a server already running, deeporg mcp add claude http://localhost:8080 registers it over HTTP.
What runs
A nested query becomes $lookup.
query {
orders(where: { status: { eq: "open" } }, order_by: { id: desc }, limit: 10) {
id
total
customer { id name }
}
}The engine sends MongoDB one pipeline: a $match on status plus the role’s filter, a $sort and $limit, and a $lookup into customers that projects only id and name. Embedded arrays queried as their own table use $unwind and $group so the parent document keeps its shape.
Limits
Where MongoDB differs.
- Some SQL features do not carry over. Counts, sums and averages run as a
$groupstage, but analytics directives (window-style rankings) and database functions are SQL-only. Check before you rely on an aggregate-heavy question being portable. - Relationships are declared. Nothing is inferred from field names; a missing declaration means a missing join.
- No schema management. Collections are discovered from your data; the engine does not create or migrate them.
- Tested version. The test suite runs against MongoDB 7.
Go deeper
Related pages.
- MongoDB in the docs: the pipeline format, cursors and ids.
- Multiple databases: one query across MongoDB and SQL.
- DeepORG vs hand-built MCP tools: why a tool per collection stops scaling.
- Database support: every dialect side by side.