aggregate
Run an aggregation pipeline on a MongoDB collection
Query and write to MongoDB from the conversation, with a schema call that shows the real field names first.
LABSCO SUMMARY
An agent guessing at field names in a schemaless collection burns several queries getting empty results back. getSchema returns the field names and their types up front, so find and aggregate get written against what the documents actually contain. Writes are single-document only — insertOne, updateOne, deleteOne — so a filter that matches more than you expected still touches one record.
A MongoDB server over one connection string: the usual reads — find, findOne, aggregate, count, distinct — single-document writes, a collection listing, and a getSchema call that reports the field names and types a collection actually holds.
MONGODB_URI, a full connection string — MongoDB Atlas and authenticated deployments both work. MONGODB_DATABASE names the default database and is optional. Installs from npm as @sourabhshegane/mongodb-mcp-that-works.
One command — npx -y @sourabhshegane/mongodb-mcp-that-works@latest
USE CASES
List the collections, then read back the field names and types instead of paging through sample documents.
Check the field names first, then run the pipeline as written and get the grouped result back.
Fetch the one document by filter, or count how many match, before anything is written.
Get the distinct values across the collection, which is faster than reading documents to find out.
Find the record by filter, confirm it is the right one, then update that single document.
Query with a filter, a sort and a limit so the model reads a page rather than the collection.
Counted once with only startup setup. Other versions, modes or optional credentials may expose a different list.
aggregateRun an aggregation pipeline on a MongoDB collection
countCount documents in a MongoDB collection
deleteOneDelete a single document from a MongoDB collection
distinctGet distinct values for a field in a MongoDB collection
findFind documents in a MongoDB collection
findOneFind a single document in a MongoDB collection
getSchemaAnalyze collection structure and return field names with types
insertOneInsert a single document into a MongoDB collection
listCollectionsList all collections in the database
updateOneUpdate a single document in a MongoDB collection
BEFORE YOU INSTALL
10 tools when we connected.
MONGODB_DATABASE in your environment
CONTEXT COST
Rated by the size of the 10 tool definitions that ride along on every turn, not by how many there are
INSTALLATION
Add the block to your client, or run the command directly.
{
"mcpServers": {
"mongodb": {
"command": "npx",
"args": [
"-y",
"@sourabhshegane/mongodb-mcp-that-works@latest"
],
"env": {
"MONGODB_URI": "mongodb+srv://<YOUR_DB_USER>:<YOUR_DB_PASSWORD>@cluster.mongodb.net/<YOUR_DB_NAME>",
"MONGODB_DATABASE": "<YOUR_MONGODB_DATABASE>"
}
}
}
}npx -y @sourabhshegane/mongodb-mcp-that-works@latest