CursorNotFound
data
resource_error
ai_generated
true
MongoDB游标未找到异常:超时后服务器上找不到游标
MongoDB CursorNotFoundException: cursor not found on server after timeout
ID: data/mongodb-cursor-timeout-exceeded
85%修复率
88%置信度
1证据数
2023-06-20首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| MongoDB 5.0 | active | — | — | — |
| MongoDB 6.0 | active | — | — | — |
| MongoDB 7.0 | active | — | — | — |
根因分析
MongoDB服务端游标的默认空闲超时时间为10分钟;如果客户端暂停迭代超过此时间,服务器会回收游标,导致下一次getMore调用失败。
English
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.
官方文档
https://www.mongodb.com/docs/manual/reference/method/cursor.noCursorTimeout/解决方案
-
Enable noCursorTimeout on the cursor to prevent server-side garbage collection, but ensure you manually close the cursor to avoid resource leaks.
-
Re-query with a filter on a timestamp field or use aggregation with $match to restart iteration from the last processed document.
无效尝试
常见但无效的做法:
-
90% 失败
The cursor still expires on the server regardless of batch size if no activity occurs.
-
85% 失败
maxTimeMS controls query runtime, not cursor lifetime.