Query collections, run aggregations, manage indexes, and debug MongoDB documents directly from Claude Code using the MongoDB MCP.
The MongoDB MCP gives Claude Code a direct connection to your MongoDB Atlas cluster or self-hosted MongoDB instance. Claude can query and aggregate documents, inspect collection schemas, manage indexes, and help you write or optimize aggregation pipelines — without opening MongoDB Compass or the Atlas UI.
mcpizy install mongodb
Provide your MongoDB connection string during setup. For Atlas clusters, use the SRV connection string from your Atlas dashboard. Ensure your IP is whitelisted in Atlas Network Access.
Find the top 5 users by order count in the last 30 days:
db.orders.aggregate([
{ $match: { createdAt: { $gte: new Date(Date.now() - 30*24*60*60*1000) } } },
{ $group: { _id: "$userId", orderCount: { $sum: 1 } } },
{ $sort: { orderCount: -1 } },
{ $limit: 5 }
]);
Claude generates and runs this aggregation via the MCP, then explains the results.
explain() on slow queries to understand index usage before adding new indexes.