# MongoDB CursorNotFoundException: cursor not found on server after timeout

- **ID:** `data/mongodb-cursor-timeout-exceeded`
- **Domain:** data
- **Category:** resource_error
- **Error Code:** `CursorNotFound`
- **Verification:** ai_generated
- **Fix Rate:** 85%

## Root Cause

MongoDB server-side cursors have a default idle timeout of 10 minutes; if the client pauses iteration beyond this time, the server garbage-collects the cursor, causing the next getMore call to fail.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| MongoDB 5.0 | active | — | — |
| MongoDB 6.0 | active | — | — |
| MongoDB 7.0 | active | — | — |

## Workarounds

1. **Enable noCursorTimeout on the cursor to prevent server-side garbage collection, but ensure you manually close the cursor to avoid resource leaks.** (95% success)
   ```
   Enable noCursorTimeout on the cursor to prevent server-side garbage collection, but ensure you manually close the cursor to avoid resource leaks.
   ```
2. **Re-query with a filter on a timestamp field or use aggregation with $match to restart iteration from the last processed document.** (78% success)
   ```
   Re-query with a filter on a timestamp field or use aggregation with $match to restart iteration from the last processed document.
   ```

## Dead Ends

- **** — The cursor still expires on the server regardless of batch size if no activity occurs. (90% fail)
- **** — maxTimeMS controls query runtime, not cursor lifetime. (85% fail)
