0
0
MongoDBquery~5 mins

Query patterns that cause collection scans in MongoDB - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a collection scan in MongoDB?
A collection scan happens when MongoDB reads every document in a collection to find those that match a query. It is slow because it checks all documents instead of using an index.
Click to reveal answer
beginner
Name a common query pattern that causes a collection scan.
Queries that do not use an index, such as searching on a field without an index or using operators that prevent index use, cause collection scans.
Click to reveal answer
intermediate
Why does using a regular expression without an index cause a collection scan?
Because MongoDB cannot use an index efficiently for regex patterns that do not start with a fixed prefix, it scans all documents to match the pattern.
Click to reveal answer
intermediate
How does querying with $not or $ne operators affect index usage?
Queries using $not or $ne often cause collection scans because these operators do not use indexes well, forcing MongoDB to check all documents.
Click to reveal answer
beginner
What is a way to avoid collection scans in MongoDB queries?
Create indexes on fields used in queries and write queries that can use those indexes, avoiding operators or patterns that prevent index use.
Click to reveal answer
Which of the following query patterns is most likely to cause a collection scan in MongoDB?
AQuery using $ne operator on a non-indexed field
BQuery using equality on an indexed field
CQuery on a field with a supporting index
DQuery using _id field
What does MongoDB do during a collection scan?
AReads documents in random order
BReads only indexed documents
CReads all documents in the collection
DReads only documents matching the query
Which operator often prevents MongoDB from using an index, causing a collection scan?
A$not
B$eq
C$gt
D$in
How can you reduce collection scans in MongoDB queries?
AAvoid creating indexes
BUse queries that match indexed fields
CUse $ne operator frequently
DScan all documents manually
Why does a regex query without a fixed prefix cause a collection scan?
ABecause regex queries never scan collections
BBecause regex always uses indexes
CBecause regex queries are faster without indexes
DBecause MongoDB cannot use indexes efficiently without a fixed prefix
Explain what causes a collection scan in MongoDB and how to avoid it.
Think about how MongoDB finds documents and what happens when no index is used.
You got /4 concepts.
    Describe how operators like $ne and $not affect MongoDB query performance.
    Consider how MongoDB searches documents when these operators are used.
    You got /3 concepts.