0
0
MongoDBquery~10 mins

Index usage verification 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 check index usage for a query on the 'users' collection.

MongoDB
db.users.find({ age: { $gt: 25 } }).[1]()
Drag options to blanks, or click blank then click option'
Aexplain
Bcount
Caggregate
Dinsert
Attempts:
3 left
💡 Hint
Common Mistakes
Using count() instead of explain() will only return the number of documents.
Using aggregate() or insert() are unrelated to checking index usage.
2fill in blank
medium

Complete the code to get the query planner information from the explain output.

MongoDB
db.orders.find({ status: 'shipped' }).explain().[1]
Drag options to blanks, or click blank then click option'
AexecutionStats
Bcursor
CserverStatus
DqueryPlanner
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing executionStats gives runtime stats, not the plan itself.
cursor and serverStatus are unrelated to query plan details.
3fill in blank
hard

Fix the error in the code to correctly check if an index is used for the query on 'products'.

MongoDB
const plan = db.products.find({ price: { $lt: 100 } }).explain().queryPlanner.[1];
print(plan.indexName);
Drag options to blanks, or click blank then click option'
AqueryPlanner
BexecutionStats
CwinningPlan
DserverStatus
Attempts:
3 left
💡 Hint
Common Mistakes
Using executionStats or serverStatus will not provide indexName.
Accessing queryPlanner directly without winningPlan does not give indexName.
4fill in blank
hard

Fill both blanks to create a query that uses explain to check if the 'email' index is used in the 'customers' collection.

MongoDB
const plan = db.customers.find({ [1]: 'example@example.com' }).explain().[2].winningPlan;
print(plan.indexName);
Drag options to blanks, or click blank then click option'
Aemail
BexecutionStats
CqueryPlanner
Dname
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'name' instead of 'email' as the filter field.
Using executionStats instead of queryPlanner to find indexName.
5fill in blank
hard

Fill all three blanks to write code that explains a query on 'inventory' collection, filters by 'category', and prints the index name used.

MongoDB
const plan = db.inventory.find({ [1]: 'electronics' }).explain().[2].[3];
print(plan.indexName);
Drag options to blanks, or click blank then click option'
Acategory
BqueryPlanner
CwinningPlan
DexecutionStats
Attempts:
3 left
💡 Hint
Common Mistakes
Using executionStats instead of queryPlanner or winningPlan.
Using wrong field name for filtering.