Challenge - 5 Problems
Index Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
Check index usage with explain()
Given a MongoDB collection
users with an index on age, what does the explain() output show when running db.users.find({age: 30}).explain()?MongoDB
db.users.find({age: 30}).explain()Attempts:
2 left
💡 Hint
Look for the
stage field in the winningPlan part of the explain output.✗ Incorrect
When an index is used, the explain output includes
stage: "IXSCAN" which means an index scan was performed instead of scanning the whole collection.❓ query_result
intermediate2:00remaining
Effect of missing index on query plan
If a MongoDB collection
orders has no index on customerId, what will db.orders.find({customerId: 123}).explain() show?MongoDB
db.orders.find({customerId: 123}).explain()Attempts:
2 left
💡 Hint
Without an index, MongoDB must scan all documents to find matches.
✗ Incorrect
If no index exists on the queried field, MongoDB performs a collection scan, shown as
stage: "COLLSCAN" in explain output.📝 Syntax
advanced2:00remaining
Identify correct syntax to create a compound index
Which option correctly creates a compound index on
category ascending and price descending in MongoDB?Attempts:
2 left
💡 Hint
Use an object with field names as keys and 1 or -1 for ascending or descending.
✗ Incorrect
The correct syntax uses an object with keys as field names and values 1 for ascending or -1 for descending order.
❓ optimization
advanced2:00remaining
Optimize query with index for range and equality
Given a collection
sales with an index on {region: 1, date: 1}, which query will use the index efficiently?Attempts:
2 left
💡 Hint
The index fields order matters: equality on first field then range on second uses index best.
✗ Incorrect
The index on
{region: 1, date: 1} is best used when the query specifies equality on region and a range on date. Option A does this correctly.🧠 Conceptual
expert3:00remaining
Understanding index intersection
If a MongoDB collection has separate indexes on
status and priority, which query can benefit from index intersection?Attempts:
2 left
💡 Hint
Index intersection combines multiple single-field indexes to answer queries with multiple conditions.
✗ Incorrect
When a query filters on multiple fields each having separate indexes, MongoDB can combine those indexes using index intersection to improve performance. Option B filters on both
status and priority.