A sequential scan, also called a collection scan, examines documents throughout a MongoDB collection to find matches when no applicable index supports the query. It can burden response time and database resources as collections grow. section 7.1
Use these guidelines when evaluating a collection scan:
- Expect MongoDB to scan the collection when any $or clause lacks suitable index support; every clause must be indexed for indexed evaluation. section 7.6.4
- Do not assume an index is always faster: indexes require index and document lookups, while a collection scan uses one lookup for broad result sets. section 7.7
- Treat the roughly 30% selectivity guideline as variable; data size and query conditions can move the useful range from about 2% to 60%. section 7.7
A growing log query
A monitoring system queries logs for one server during the past week. An index on timestamp may be fast when the result set is small, but the same query can become slow as accumulated logs make the result set large. section 7.7
db.movies.find({
$or: [
{ year: 1914 },
{ "imdb.rating": { $gt: 7 } }
]
}).explain("executionStats")
Inspect executionStats for an $or query to verify whether MongoDB performs a collection scan or uses supported indexes. section 7.6.4
db.movies.createIndex({ "imdb.rating": 1 })
Create an index for the imdb.rating clause so every $or condition has index support and the collection scan can be avoided. section 7.6.4


