mongodb
runtime_error
ai_generated
true
MongoServerError:QueryExceededTimeLimit:对命名空间 test.orders 的查询超过了从节点读取的 5000 毫秒时间限制
MongoServerError: QueryExceededTimeLimit: query on namespace test.orders exceeded time limit of 5000ms for secondary read
ID: mongodb/query-exceeded-time-limit-for-secondary-read
82%修复率
87%置信度
1证据数
2025-03-22首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| mongodb-5.0 | active | — | — | — |
| mongodb-6.0 | active | — | — | — |
| mongodb-7.0 | active | — | — | — |
| mongodb-8.0 | active | — | — | — |
根因分析
由于高负载或缺少索引,从节点上的读取操作耗时超过配置的 maxTimeMS。
English
A read operation on a secondary node took longer than the configured maxTimeMS due to high load or missing indexes.
官方文档
https://www.mongodb.com/docs/manual/reference/method/cursor.maxTimeMS/解决方案
-
Add an index that covers the query fields using db.collection.createIndex() to reduce scan time.
-
Increase maxTimeMS for specific queries using .maxTimeMS(10000) in the application code.
-
Use a read preference tag to route queries to less loaded secondary nodes.
无效尝试
常见但无效的做法:
-
50% 失败
Setting readPreference to primary only increases load on the primary and does not fix the underlying query performance.
-
50% 失败
Increasing maxTimeMS globally can mask performance issues and lead to resource exhaustion.
-
50% 失败
Disabling secondary reads entirely reduces read throughput and defeats the purpose of replication.