在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
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之前,aggregate命令不支持游标,因此必须将其添加为一个选项,以避免破坏现有应用程序.
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屋!