mongodb resource_error ai_generated true

MongoServerError: OplogQueryNoMoreCursors: no more cursors available for query on namespace local.oplog.rs

ID: mongodb/oplog-query-no-more-cursors

Also available as: JSON · Markdown · 中文
85%Fix Rate
88%Confidence
1Evidence
2024-02-15First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
MongoDB 6.0 active
MongoDB 7.0 active

Root Cause

The oplog query exhausted all available cursors due to a long-running change stream or tailing cursor without proper cleanup.

generic

中文

由于长时间运行的变更流或尾随游标未正确清理,oplog 查询耗尽了所有可用游标。

Official Documentation

https://www.mongodb.com/docs/manual/reference/operator/aggregation/changeStream/

Workarounds

  1. 90% success Close stale change stream cursors by killing idle cursors: db.currentOp({‘$all’: true}) then db.killOp(opid) for cursors with secs_running > 300.
    Close stale change stream cursors by killing idle cursors: db.currentOp({‘$all’: true}) then db.killOp(opid) for cursors with secs_running > 300.
  2. 85% success Reduce maxTimeMS on change streams to force automatic cursor expiration: db.collection.watch([], {maxTimeMS: 60000}).
    Reduce maxTimeMS on change streams to force automatic cursor expiration: db.collection.watch([], {maxTimeMS: 60000}).

中文步骤

  1. 关闭过期的变更流游标:使用 db.currentOp({'$all': true}) 查找游标,然后对 secs_running > 300 的游标执行 db.killOp(opid)。
  2. 减少变更流的 maxTimeMS 以强制自动过期游标:db.collection.watch([], {maxTimeMS: 60000})。

Dead Ends

Common approaches that don't work:

  1. 70% fail

    Restarting the mongod process temporarily clears cursors but doesn't prevent recurrence.

  2. 90% fail

    Increasing oplog size does not affect cursor count, only storage capacity.

  3. 80% fail

    Setting cursorTimeoutMillis to a higher value makes the problem worse by keeping cursors open longer.