在 Mongo 2.6 和 Pymongo 2.7.1 上使用 maxTimeMS 参数和聚合查询 [英] Using maxTimeMS parameter with aggregation queries on Mongo 2.6 and Pymongo 2.7.1
问题描述
我无法在 Mongo 2.6 和 Pymongo 2.7.1 中使用 maxTimeMS 参数
I'm unable to use maxTimeMS parameter with Mongo 2.6 and Pymongo 2.7.1
根据此页面上的文档 Official Mongodb Aggregation Page 聚合方法应该返回一个 Cursor
对象.但是,当我使用 pymongo
2.7.1 在 mongod
实例(2.6+)上本地运行查询时,我得到一个 dict
对象!
As per the documentation on this page Official Mongodb Aggregation Page the aggregation method should return a Cursor
object. However, when I run the query locally on a mongod
instance (2.6+) with pymongo
2.7.1, I get a dict
object!
在[14]中:obj = coll.aggregate({'$group': {'_id': '$l', 'n': {'$sum':1}}})
In [14]: obj = coll.aggregate({'$group': {'_id': '$l', 'n': {'$sum': 1}}})
输入[15]:类型(obj)输出[15]:字典
In [15]: type(obj) Out[15]: dict
谁能帮我理解这里发生了什么?
Can anyone help me understand what is happening here?
推荐答案
是的,你可以使用 maxTimeMS 和 pymongo 聚合.
Yes, you can use maxTimeMS with pymongo aggregation.
c.foo.bar.aggregate([], maxTimeMS=1000)
{u'ok': 1.0, u'result': []}
如果你想要一个光标:
for result in c.foo.bar.aggregate([], cursor={}, maxTimeMS=1000):
... print result
在 MongoDB 2.6 之前,聚合命令不支持游标,因此必须将其添加为选项以避免破坏现有应用程序.
The aggregate command didn't support cursors before MongoDB 2.6 so it had to be added as an option to avoid breaking existing applications.
这篇关于在 Mongo 2.6 和 Pymongo 2.7.1 上使用 maxTimeMS 参数和聚合查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!