Challenge - 5 Problems
Master of Collection Scans
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
Which query causes a collection scan due to missing index?
Given a collection
users with an index on age, which query will cause a collection scan?MongoDB
db.users.find({name: 'Alice'})Attempts:
2 left
💡 Hint
Think about which field has an index and which does not.
✗ Incorrect
Only queries filtering on the indexed field
age can use the index. Querying by name without an index causes a collection scan.❓ query_result
intermediate2:00remaining
Which query pattern causes a collection scan despite an index?
Assuming an index exists on
status, which query will still cause a collection scan?MongoDB
db.orders.find({status: {$ne: 'shipped'}})Attempts:
2 left
💡 Hint
Think about how negation operators affect index usage.
✗ Incorrect
The $ne operator cannot use indexes efficiently and causes a collection scan even if an index exists on the field.
📝 Syntax
advanced2:00remaining
Which query syntax causes a runtime error due to invalid operator usage?
Identify the query that will cause a runtime error in MongoDB due to incorrect operator usage.
Attempts:
2 left
💡 Hint
Check if the operator is valid in MongoDB query language.
✗ Incorrect
MongoDB does not support the $between operator. Using it causes a runtime error.
❓ optimization
advanced2:00remaining
Which query pattern can be optimized to avoid collection scan?
Given a collection with an index on
category, which query can be rewritten to use the index and avoid a collection scan?Attempts:
2 left
💡 Hint
Consider which operators allow index usage.
✗ Incorrect
The $in operator can use indexes efficiently. Other operators like $exists, $ne, and $not often cause collection scans.
🧠 Conceptual
expert3:00remaining
Why does a query with a regex pattern cause a collection scan?
Consider a collection with an index on the
username field. Why does the query db.users.find({username: /admin/}) cause a collection scan?Attempts:
2 left
💡 Hint
Think about how MongoDB uses indexes with regex patterns.
✗ Incorrect
MongoDB can use indexes for regex queries only if the pattern is a simple prefix without special regex characters. Complex patterns cause collection scans.