mongodb
runtime_error
ai_generated
true
MongoServerError: 查询模式未被任何索引覆盖
MongoServerError: query pattern not covered by any index
ID: mongodb/query-pattern-not-covered-by-index
90%修复率
85%置信度
1证据数
2024-01-10首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| mongodb-5.0 | active | — | — | — |
| mongodb-6.0 | active | — | — | — |
| mongodb-7.0 | active | — | — | — |
根因分析
查询的过滤或排序模式与任何现有索引不匹配,导致全集合扫描。
English
A query's filter or sort pattern does not match any existing index, forcing a collection scan.
官方文档
https://www.mongodb.com/docs/manual/indexes/#indexes-and-query-performance解决方案
-
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.
无效尝试
常见但无效的做法:
-
90% 失败
Creating an index on a different field does not help; the index must match the query pattern.
-
85% 失败
Using hint() to force an unrelated index still results in a scan.