# MongoServerError: QueryExceededTimeLimit: query on namespace test.orders exceeded time limit of 5000ms for secondary read

- **ID:** `mongodb/query-exceeded-time-limit-for-secondary-read`
- **Domain:** mongodb
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 82%

## Root Cause

A read operation on a secondary node took longer than the configured maxTimeMS due to high load or missing indexes.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| mongodb-5.0 | active | — | — |
| mongodb-6.0 | active | — | — |
| mongodb-7.0 | active | — | — |
| mongodb-8.0 | active | — | — |

## Workarounds

1. **Add an index that covers the query fields using db.collection.createIndex() to reduce scan time.** (90% success)
   ```
   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.** (80% success)
   ```
   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.** (75% success)
   ```
   Use a read preference tag to route queries to less loaded secondary nodes.
   ```

## Dead Ends

- **** — 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. (50% fail)
