# MongoDB游标未找到异常：超时后服务器上找不到游标

- **ID:** `data/mongodb-cursor-timeout-exceeded`
- **领域:** data
- **类别:** resource_error
- **错误码:** `CursorNotFound`
- **验证级别:** ai_generated
- **修复率:** 85%

## 根因

MongoDB服务端游标的默认空闲超时时间为10分钟；如果客户端暂停迭代超过此时间，服务器会回收游标，导致下一次getMore调用失败。

## 版本兼容性

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

## 解决方案

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

## 无效尝试

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