0
0
MongoDBquery~10 mins

Explain plan analysis (queryPlanner, executionStats) in MongoDB - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to get the explain plan for a MongoDB query.

MongoDB
db.collection.find({ age: { $gt: 25 } }).[1]()
Drag options to blanks, or click blank then click option'
AshowPlan
BexplainPlan
Cexplain
DqueryExplain
Attempts:
3 left
💡 Hint
Common Mistakes
Using a method name that does not exist like 'explainPlan'.
Trying to use 'showPlan' or 'queryExplain' which are not valid.
2fill in blank
medium

Complete the code to get the execution statistics from the explain output.

MongoDB
const result = db.collection.find({ status: 'active' }).explain();
const stats = result.[1];
Drag options to blanks, or click blank then click option'
AexecutionStats
BqueryPlanner
CplanSummary
DexecutionPlan
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'queryPlanner' which only shows the plan, not execution details.
Using 'planSummary' which is a brief summary, not detailed stats.
3fill in blank
hard

Fix the error in accessing the winning plan from the explain output.

MongoDB
const plan = db.collection.find({}).explain().[1].winningPlan;
Drag options to blanks, or click blank then click option'
AexecutionStats
BplanDetails
CexecutionPlan
DqueryPlanner
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to get winningPlan from 'executionStats' which does not contain it.
Using non-existent fields like 'executionPlan' or 'planDetails'.
4fill in blank
hard

Fill both blanks to get the total number of documents examined and the number returned from execution stats.

MongoDB
const stats = db.collection.find({}).explain().[1];
const examined = stats.[2];
Drag options to blanks, or click blank then click option'
AexecutionStats
BqueryPlanner
CtotalDocsExamined
DnReturned
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'queryPlanner' instead of 'executionStats' for runtime data.
Using 'nReturned' instead of 'totalDocsExamined' for documents examined.
5fill in blank
hard

Fill all three blanks to get the number of documents returned, the execution time in milliseconds, and the stage name of the winning plan.

MongoDB
const explain = db.collection.find({}).explain();
const returned = explain.executionStats.[1];
const timeMs = explain.executionStats.[2];
const stage = explain.queryPlanner.winningPlan.[3];
Drag options to blanks, or click blank then click option'
AnReturned
BexecutionTimeMillis
Cstage
DtotalDocsExamined
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up fields between executionStats and queryPlanner.
Using 'totalDocsExamined' instead of 'nReturned' for returned documents.