MongoDB MCP Server

explain_query

Get the execution plan for a query.

Helps understand:

  • How MongoDB will execute the query
  • Which indexes will be used
  • Number of documents examined
  • Execution stages and timing

Use this to optimize slow queries.

Input Schema

NameRequiredDescriptionDefault
collectionYesCollection name
databaseNoDatabase name (optional if default database is configured)
filterYesMongoDB query filter to explain
projectionNoMongoDB projection (optional)
sortNoMongoDB sort specification (optional)

Input Schema (JSON Schema)

{ "properties": { "collection": { "description": "Collection name", "type": "string" }, "database": { "description": "Database name (optional if default database is configured)", "type": "string" }, "filter": { "description": "MongoDB query filter to explain", "type": "object" }, "projection": { "description": "MongoDB projection (optional)", "type": "object" }, "sort": { "description": "MongoDB sort specification (optional)", "type": "object" } }, "required": [ "collection", "filter" ], "type": "object" }