0
0
MongoDBquery~20 mins

Explain plan analysis (queryPlanner, executionStats) in MongoDB - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Explain Plan Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2: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 */ }
}
AIt contains the error messages if the query failed.
BIt shows the actual data returned by the query.
CIt describes how MongoDB plans to execute the query, including indexes used.
DIt lists all documents scanned during query execution.
Attempts:
2 left
💡 Hint
Think about what a 'planner' does before running a query.
query_result
intermediate
2: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
  }
}
AThe total number of documents in the collection.
BThe number of index keys scanned but not returned.
CThe number of queries run on the server.
DThe number of documents matched and returned by the query.
Attempts:
2 left
💡 Hint
Focus on what 'returned' means in a query context.
🧠 Conceptual
advanced
2:00remaining
Difference between queryPlanner and executionStats
Which statement best describes the difference between queryPlanner and executionStats in MongoDB's explain output?
AqueryPlanner shows the database schema; executionStats shows user permissions.
BqueryPlanner shows the planned steps before running; executionStats shows what actually happened during execution.
CqueryPlanner shows server errors; executionStats shows network latency.
DqueryPlanner shows the documents returned; executionStats shows the query syntax.
Attempts:
2 left
💡 Hint
Think about planning vs doing.
📝 Syntax
advanced
2: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?
Adb.users.find({ age: { $gt: 30 } }).explain('executionStats')
Bdb.users.explain('executionStats').find({ age: { $gt: 30 } })
Cdb.users.find.explain({ age: { $gt: 30 } }, 'executionStats')
Ddb.users.find({ age: { $gt: 30 } }).explain('allPlansExecution')
Attempts:
2 left
💡 Hint
Remember the order of method calls for explain.
optimization
expert
2: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?
AThe query is inefficient because it examines as many documents as index keys, likely scanning many documents.
BThe query is efficient because it uses an index and examines few documents.
CThe query is efficient because it scanned all documents quickly.
DThe query failed because totalDocsExamined cannot equal totalKeysExamined.
Attempts:
2 left
💡 Hint
Think about what it means if keys examined equals documents examined.