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

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

generic

官方文档

https://www.mongodb.com/docs/manual/reference/method/cursor.maxTimeMS/

解决方案

  1. Add an index that covers the query fields using db.collection.createIndex() to reduce scan time.
  2. Increase maxTimeMS for specific queries using .maxTimeMS(10000) in the application code.
  3. Use a read preference tag to route queries to less loaded secondary nodes.

无效尝试

常见但无效的做法:

  1. 50% 失败

    Setting readPreference to primary only increases load on the primary and does not fix the underlying query performance.

  2. 50% 失败

    Increasing maxTimeMS globally can mask performance issues and lead to resource exhaustion.

  3. 50% 失败

    Disabling secondary reads entirely reduces read throughput and defeats the purpose of replication.