# MongoServerError：QueryExceededTimeLimit：对命名空间 test.orders 的查询超过了从节点读取的 5000 毫秒时间限制

- **ID:** `mongodb/query-exceeded-time-limit-for-secondary-read`
- **领域:** mongodb
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 82%

## 根因

由于高负载或缺少索引，从节点上的读取操作耗时超过配置的 maxTimeMS。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| mongodb-5.0 | active | — | — |
| mongodb-6.0 | active | — | — |
| mongodb-7.0 | active | — | — |
| mongodb-8.0 | active | — | — |

## 解决方案

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.
   ```

## 无效尝试

- **** — 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. (50% 失败率)
