mongodb
runtime_error
ai_generated
true
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%Fix Rate
87%Confidence
1Evidence
2025-03-22First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| mongodb-5.0 | active | — | — | — |
| mongodb-6.0 | active | — | — | — |
| mongodb-7.0 | active | — | — | — |
| mongodb-8.0 | active | — | — | — |
Root Cause
A read operation on a secondary node took longer than the configured maxTimeMS due to high load or missing indexes.
generic中文
由于高负载或缺少索引,从节点上的读取操作耗时超过配置的 maxTimeMS。
Official Documentation
https://www.mongodb.com/docs/manual/reference/method/cursor.maxTimeMS/Workarounds
-
90% success Add an index that covers the query fields using db.collection.createIndex() to reduce scan time.
Add an index that covers the query fields using db.collection.createIndex() to reduce scan time.
-
80% success Increase maxTimeMS for specific queries using .maxTimeMS(10000) in the application code.
Increase maxTimeMS for specific queries using .maxTimeMS(10000) in the application code.
-
75% success Use a read preference tag to route queries to less loaded secondary nodes.
Use a read preference tag to route queries to less loaded secondary nodes.
中文步骤
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.
Dead Ends
Common approaches that don't work:
-
50% fail
Setting readPreference to primary only increases load on the primary and does not fix the underlying query performance.
-
50% fail
Increasing maxTimeMS globally can mask performance issues and lead to resource exhaustion.
-
50% fail
Disabling secondary reads entirely reduces read throughput and defeats the purpose of replication.