mongodb
runtime_error
ai_generated
true
MongoServerError: query pattern not covered by any index
ID: mongodb/query-pattern-not-covered-by-index
90%Fix Rate
85%Confidence
1Evidence
2024-01-10First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| mongodb-5.0 | active | — | — | — |
| mongodb-6.0 | active | — | — | — |
| mongodb-7.0 | active | — | — | — |
Root Cause
A query's filter or sort pattern does not match any existing index, forcing a collection scan.
generic中文
查询的过滤或排序模式与任何现有索引不匹配,导致全集合扫描。
Official Documentation
https://www.mongodb.com/docs/manual/indexes/#indexes-and-query-performanceWorkarounds
-
90% success Create a compound index that matches the query filter and sort fields in the correct order.
Create a compound index that matches the query filter and sort fields in the correct order.
-
95% success Use explain() to analyze the query and determine the optimal index.
Use explain() to analyze the query and determine the optimal index.
中文步骤
Create a compound index that matches the query filter and sort fields in the correct order.
Use explain() to analyze the query and determine the optimal index.
Dead Ends
Common approaches that don't work:
-
90% fail
Creating an index on a different field does not help; the index must match the query pattern.
-
85% fail
Using hint() to force an unrelated index still results in a scan.