Challenge - 5 Problems
MongoDB Scan Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
What is the output of this MongoDB query scan?
Consider a collection users with documents containing
age and name. The query db.users.find({ age: { $gt: 30 } }) is run without any indexes. What kind of scan does MongoDB perform and what documents are returned?MongoDB
db.users.find({ age: { $gt: 30 } })Attempts:
2 left
💡 Hint
Think about what happens when no index supports the query condition.
✗ Incorrect
Without an index on the age field, MongoDB must scan every document in the collection (collection scan) to find those where age is greater than 30.
🧠 Conceptual
intermediate2:00remaining
How does MongoDB use indexes to scan documents?
If a collection has an index on the
status field, what type of scan does MongoDB perform when running db.orders.find({ status: 'shipped' })?Attempts:
2 left
💡 Hint
Indexes help MongoDB find documents faster by scanning only relevant entries.
✗ Incorrect
When an index exists on the queried field, MongoDB uses an index scan to efficiently locate matching documents without scanning the entire collection.
📝 Syntax
advanced2:00remaining
Which MongoDB query syntax will cause an error when scanning documents?
Identify the query that will cause a syntax error when scanning documents in MongoDB.
Attempts:
2 left
💡 Hint
Check the use of $ sign in field names.
✗ Incorrect
Field names in queries cannot start with a $ unless it is an operator. Using $price as a field name causes a syntax error.
❓ optimization
advanced2:00remaining
Which query will result in the most efficient document scan?
Given a collection with an index on
category and price, which query will use the index most efficiently to scan documents?Attempts:
2 left
💡 Hint
Using multiple indexed fields in a query improves scan efficiency.
✗ Incorrect
Querying on both indexed fields allows MongoDB to use a compound index scan, reducing the number of documents scanned.
🔧 Debug
expert2:00remaining
Why does this MongoDB query scan all documents despite an index existing?
A collection has an index on
status. The query db.orders.find({ status: { $in: ['shipped', 'delivered'] } }) scans all documents instead of using the index. Why?Attempts:
2 left
💡 Hint
Consider how MongoDB decides to use indexes based on query selectivity.
✗ Incorrect
If the query matches a large portion of documents, MongoDB may choose a collection scan over an index scan for efficiency.