Challenge - 5 Problems
Explain Plan Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
Understanding queryPlanner output
Given the following MongoDB explain output snippet, what does the
queryPlanner section primarily describe?MongoDB
{
"queryPlanner": {
"plannerVersion": 1,
"namespace": "shop.products",
"indexFilterSet": false,
"parsedQuery": { "category": { "$eq": "books" } },
"winningPlan": {
"stage": "IXSCAN",
"keyPattern": { "category": 1 },
"indexName": "category_1",
"isMultiKey": false
}
},
"executionStats": { /* omitted for brevity */ }
}Attempts:
2 left
💡 Hint
Think about what a 'planner' does before running a query.
✗ Incorrect
The queryPlanner section explains the strategy MongoDB will use to run the query, such as which indexes it will use and the stages involved.
❓ query_result
intermediate2:00remaining
Interpreting executionStats nReturned value
In the
executionStats section of a MongoDB explain output, what does the nReturned field represent?MongoDB
{
"executionStats": {
"nReturned": 5,
"executionTimeMillis": 3,
"totalKeysExamined": 10,
"totalDocsExamined": 5
}
}Attempts:
2 left
💡 Hint
Focus on what 'returned' means in a query context.
✗ Incorrect
nReturned tells how many documents the query actually returned to the user after execution.
🧠 Conceptual
advanced2:00remaining
Difference between queryPlanner and executionStats
Which statement best describes the difference between
queryPlanner and executionStats in MongoDB's explain output?Attempts:
2 left
💡 Hint
Think about planning vs doing.
✗ Incorrect
queryPlanner describes the intended plan before running the query, while executionStats reports the real performance and results after running.
📝 Syntax
advanced2:00remaining
Identify the error in explain command usage
Which of the following MongoDB commands will correctly return the explain plan with execution statistics for a find query on collection
users filtering by age > 30?Attempts:
2 left
💡 Hint
Remember the order of method calls for explain.
✗ Incorrect
The explain method is called on the cursor returned by find, with the verbosity string as argument.
❓ optimization
expert2:00remaining
Analyzing executionStats for query optimization
You run a query with explain('executionStats') and see
totalKeysExamined: 10000 and totalDocsExamined: 10000. What does this suggest about the query's efficiency?Attempts:
2 left
💡 Hint
Think about what it means if keys examined equals documents examined.
✗ Incorrect
If totalDocsExamined equals totalKeysExamined and both are large, it means the query scanned many documents, possibly due to poor index usage or no filtering.