0
0
MongoDBquery~20 mins

Index intersection behavior in MongoDB - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Index Intersection Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
Index Intersection Query Result

Given a MongoDB collection products with indexes on category and price, what documents will be returned by this query?

{ category: "electronics", price: { $lt: 100 } }

Assume documents:

[{_id:1, category:"electronics", price: 90}, {_id:2, category:"electronics", price: 150}, {_id:3, category:"furniture", price: 80}]
MongoDB
db.products.find({ category: "electronics", price: { $lt: 100 } })
A[{_id:1, category:"electronics", price: 90}]
B[{_id:1, category:"electronics", price: 90}, {_id:2, category:"electronics", price: 150}]
C[{_id:3, category:"furniture", price: 80}]
D[]
Attempts:
2 left
💡 Hint

Think about which documents satisfy both conditions.

🧠 Conceptual
intermediate
1:30remaining
Understanding Index Intersection

What does MongoDB's index intersection feature do?

ACombines multiple single-field indexes to satisfy a query with multiple conditions.
BRemoves unused indexes from the database.
CCreates a new compound index automatically for every query.
DMerges documents from different collections.
Attempts:
2 left
💡 Hint

Think about how MongoDB uses indexes to speed up queries with multiple filters.

📝 Syntax
advanced
2:00remaining
Correct Index Creation Syntax

Which option correctly creates two single-field indexes on category and price in MongoDB?

Adb.products.createIndex(["category", "price"])
Bdb.products.createIndex({ category: "asc", price: "asc" })
Cdb.products.createIndex({ category: 1 }); db.products.createIndex({ price: 1 })
Ddb.products.createIndex({ category: 1, price: 1 })
Attempts:
2 left
💡 Hint

Remember how to create single-field indexes separately.

optimization
advanced
2:30remaining
Improving Query Performance with Index Intersection

You have a query filtering on status and date. You currently have single-field indexes on both fields. Which action will most likely improve query performance?

AAdd a single-field index on an unrelated field.
BDrop both single-field indexes and rely on collection scan.
CCreate a text index on <code>status</code>.
DCreate a compound index on <code>{ status: 1, date: 1 }</code>.
Attempts:
2 left
💡 Hint

Think about how compound indexes compare to index intersection.

🔧 Debug
expert
3:00remaining
Diagnosing Unexpected Query Performance

A query filtering on type and region is slow despite having single-field indexes on both. Which is the most likely cause?

AThe single-field indexes are compound indexes, causing conflicts.
BMongoDB is not using index intersection because the query uses an $or operator incorrectly.
CThe collection is sharded, disabling index intersection.
DThe query uses a $text search, which ignores indexes.
Attempts:
2 left
💡 Hint

Consider how $or affects index usage.