Challenge - 5 Problems
Advanced Indexing Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
Find documents using a compound index
Given a MongoDB collection users with a compound index on
Which option correctly describes the query plan's index usage?
{ age: 1, city: 1 }, what is the output of this query?db.users.find({ age: 30, city: "New York" }).explain("executionStats")Which option correctly describes the query plan's index usage?
Attempts:
2 left
💡 Hint
Think about how compound indexes work with multiple fields in the query.
✗ Incorrect
A compound index on { age: 1, city: 1 } allows efficient queries that specify both fields. The query uses the index to quickly find matching documents without scanning the whole collection.
🧠 Conceptual
intermediate1:30remaining
Why use multikey indexes?
In MongoDB, which situation requires a multikey index to improve query performance?
Attempts:
2 left
💡 Hint
Think about how MongoDB indexes array fields.
✗ Incorrect
Multikey indexes are used when a field contains arrays. MongoDB indexes each element of the array separately to allow efficient queries on array contents.
📝 Syntax
advanced2:00remaining
Identify the correct syntax for creating a partial index
Which option shows the correct MongoDB command to create a partial index on the
orders collection for documents where status is "pending"?Attempts:
2 left
💡 Hint
Check the exact option name and syntax for partialFilterExpression.
✗ Incorrect
The correct syntax uses the option name 'partialFilterExpression' with a valid query expression like { status: { $eq: "pending" } }.
❓ optimization
advanced2:00remaining
Choosing the best index for a frequent query
You have a collection
Which index will optimize this query best?
products with fields category, price, and stock. The most frequent query is:db.products.find({ category: "electronics", price: { $lt: 500 } })Which index will optimize this query best?
Attempts:
2 left
💡 Hint
Think about which fields appear in the query filter and their order in the index.
✗ Incorrect
A compound index on { category: 1, price: 1 } supports queries filtering by category and price efficiently. The order matters: category first, then price.
🔧 Debug
expert2:30remaining
Why does this index not improve query performance?
A developer created this index:
But the query
still performs a collection scan. Why?
db.sales.createIndex({ date: 1, total: 1 })But the query
db.sales.find({ total: { $gt: 100 } })still performs a collection scan. Why?
Attempts:
2 left
💡 Hint
Remember how MongoDB uses the prefix of compound indexes.
✗ Incorrect
MongoDB can only use a compound index if the query filters on the first field in the index. Since the query filters only on total (the second field), the index is not used.