是否可以在 Pymongo 中创建一个没有光标超时的聚合?

2022-01-20 00:00:00 python pymongo find aggregate

问题描述

聚合看起来像:

res = Things.objects._collection.aggregate(pipeline,
            allowDiskUse=True,
            batchSize=101,
            noCursorTimeout=True
        )

失败了

OperationFailure:无法识别的字段noCursorTimeout"

OperationFailure: unrecognized field 'noCursorTimeout'

从 Pymongo 文档中可以看出 no_cursor_timeout 可以与 find() 一起使用,但是我一直没有成功为 aggregate() 找到可比较的 **kwargs.

It appears from the Pymongo documentation that no_cursor_timeout can be used with find(), however I have been unsuccessful locating a comparable **kwargs for aggregate().

我不想使用 setParameter 或 maxTimeMS.

I do not want to use setParameter or maxTimeMS.

更新:

来自 MongoDB 的 Jira 站点:SERVER-15042

From MongoDB's Jira Site: SERVER-15042

OP_QUERY 标头中的 NoCursorTimeout 位可防止服务器关闭空闲超过 10 分钟的游标.如果客户可能花费超过 10 分钟来处理一批结果,则可以设置此位.

The NoCursorTimeout bit in the OP_QUERY header prevents the server from closing a cursor that's idle for more than 10 minutes. Clients can set this bit if they may spend more than 10 minutes processing a batch of results.

aggregate"和parallelCollectionScan"命令也应该允许客户端关闭光标超时.

The "aggregate" and "parallelCollectionScan" commands should allow the client to turn off cursor timeouts, too.

对这张票的回应是:

我们故意不支持 noCursorTimeout.理由当我们实现游标保持活动时,需要这个就会消失.那将在 SERVER-6036 中跟踪工作.

We intentionally do not support noCursorTimeout. The rationale for needing this will go away when we implement cursor keepalive. That work will be tracked in SERVER-6036.

查看 SERVER-6036:

  • 更新时间:2016 年 9 月 14 日下午 3:53:05 GMT+0000
  • 状态:开放
  • 解决方案:未解决
  • 修复版本/s:已计划但未计划

如果我已正确阅读文档,则聚合()尚不存在游标无超时选项.

If I have read the documents correctly, a cursor no timeout option does not exist yet for aggregate().


解决方案

你是对的,不能在单个聚合游标上禁用游标超时.但是我们提供了一个全局配置设置,cursorTimeoutMillis,您可以将其增加到一个大数字:

You're correct, cursor timeout can't be disabled on individual aggregation cursors. But we've provided a global config setting, cursorTimeoutMillis, that you can increase to a large number:

mongod --setParameter cursorTimeoutMillis=600000  # 10 minutes

请参阅 SERVER-8188 了解 MongoDB 版本信息,以及如何在以下位置设置此参数运行时.

See SERVER-8188 for MongoDB version info, and how to set this parameter at runtime.

相关文章