The classic query engine is MongoDB’s original engine for planning and executing database operations. MongoDB selects it automatically when a query does not meet the criteria for the slot-based query engine; applications cannot choose it manually. section 7.1.1
Use these signals to identify and assess classic-engine execution:
- Inspect explain output: slot-based execution includes explain.queryPlanner.winningPlan.slotBasedPlan, while classic-engine results do not include that field. section 7.1.1
- Check MongoDB logs for queryFramework: "classic" identifies classic execution, while "sbe" identifies slot-based execution. section 7.1.1
- Treat engine choice as a performance consideration: the slot-based engine usually uses less CPU and memory and performs better, but the classic engine handles queries outside its eligibility criteria. section 7.1.1
Check the execution engine
Run db.collection.find({ yourField: "value" }).explain("executionStats") to inspect the winning plan and execution statistics. Review the output for slotBasedPlan; if it is absent, check the logs for queryFramework: "classic". The same explain output can show nReturned, executionTimeMillis, totalKeysExamined, and totalDocsExamined for performance diagnosis. 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 verbosity when investigating which plan and engine MongoDB used. section 7.1.1
