An execution plan is MongoDB’s strategy and sequence of operations for processing a query and returning results. The query planner compares available strategies, uses indexes when suitable, and selects a winning plan that balances speed and resource use. Without a suitable index, it may perform a full collection scan, examining every document. section 7.1
Read an execution plan by checking its planning behavior and operation stages:
- Inspect the plan tree: lower stages access collections or indexes, middle stages process retrieved data, and the top stage returns results. section 7.1.1
- Look for index-backed stages such as IXSCAN followed by FETCH, rather than an inefficient full collection scan. section 7.1 section 7.1.1
- Use execution statistics to compare returned documents, examined keys, examined documents, and execution time. section 7.1.1
- Remember that MongoDB tests available strategies during a trial phase and caches the selected plan for a query shape; cached entries can be missing, inactive, or active. section 7.1
Inspecting a query
Run db.collection.find({ yourField: "value" }).explain("executionStats") to see the chosen plan and its runtime measurements. A typical result uses IXSCAN on yourField_1, passes matching keys to FETCH, returns one document, examines one key and document, and reports executionTimeMillis. section 7.1.1
Listing 7.1 Appending the MongoDB explain () method
db.collection.find(
{ yourField: "value" }
).explain() // Explain the default query planner information
db.collection.find(
{ yourField: "value" }
).explain(
"executionStats" // Explain the query execution statistics
)
db.collection.find(
{ yourField: "value" }
).explain(
"allPlansExecution" // Explain the query execution
➥plan with all possible query plans
)
Compare queryPlanner, executionStats, and allPlansExecution modes through copyable mongosh commands. section 7.1.1



