mongodb runtime_error ai_generated true

MongoServerError: 查询模式未被任何索引覆盖

MongoServerError: query pattern not covered by any index

ID: mongodb/query-pattern-not-covered-by-index

其他格式: JSON · Markdown 中文 · English
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.

generic

官方文档

https://www.mongodb.com/docs/manual/indexes/#indexes-and-query-performance

解决方案

  1. Create a compound index that matches the query filter and sort fields in the correct order.
  2. Use explain() to analyze the query and determine the optimal index.

无效尝试

常见但无效的做法:

  1. 90% 失败

    Creating an index on a different field does not help; the index must match the query pattern.

  2. 85% 失败

    Using hint() to force an unrelated index still results in a scan.