CursorNotFound
data
resource_error
ai_generated
true
MongoDB CursorNotFoundException: cursor not found on server after timeout
ID: data/mongodb-cursor-timeout-exceeded
85%Fix Rate
88%Confidence
1Evidence
2023-06-20First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| MongoDB 5.0 | active | — | — | — |
| MongoDB 6.0 | active | — | — | — |
| MongoDB 7.0 | active | — | — | — |
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.
generic中文
MongoDB服务端游标的默认空闲超时时间为10分钟;如果客户端暂停迭代超过此时间,服务器会回收游标,导致下一次getMore调用失败。
Official Documentation
https://www.mongodb.com/docs/manual/reference/method/cursor.noCursorTimeout/Workarounds
-
95% success Enable noCursorTimeout on the cursor to prevent server-side garbage collection, but ensure you manually close the cursor to avoid resource leaks.
Enable noCursorTimeout on the cursor to prevent server-side garbage collection, but ensure you manually close the cursor to avoid resource leaks.
-
78% success Re-query with a filter on a timestamp field or use aggregation with $match to restart iteration from the last processed document.
Re-query with a filter on a timestamp field or use aggregation with $match to restart iteration from the last processed document.
中文步骤
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.
Dead Ends
Common approaches that don't work:
-
90% fail
The cursor still expires on the server regardless of batch size if no activity occurs.
-
85% fail
maxTimeMS controls query runtime, not cursor lifetime.