mongodb resource_error ai_generated true

MongoServerError: OplogQueryNoMoreCursors: 命名空间 local.oplog.rs 的查询没有更多可用游标

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

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

其他格式: JSON · Markdown 中文 · English
85%修复率
88%置信度
1证据数
2024-02-15首次发现

版本兼容性

版本状态引入弃用备注
MongoDB 6.0 active
MongoDB 7.0 active

根因分析

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

English

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

generic

官方文档

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

解决方案

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

无效尝试

常见但无效的做法:

  1. 70% 失败

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

  2. 90% 失败

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

  3. 80% 失败

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