Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using maxTimeMS parameter with aggregation queries on Mongo 2.6 and Pymongo 2.7.1

  • 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!

In [14]: obj = coll.aggregate({'$group': {'_id': '$l', 'n': {'$sum': 1}}})

In [15]: type(obj) Out[15]: dict

Can anyone help me understand what is happening here?

like image 762
VaidAbhishek Avatar asked Oct 18 '25 11:10

VaidAbhishek


1 Answers

Yes, you can use maxTimeMS with pymongo aggregation.

c.foo.bar.aggregate([], maxTimeMS=1000)
{u'ok': 1.0, u'result': []}

If you want a cursor:

for result in c.foo.bar.aggregate([], cursor={}, maxTimeMS=1000):
... print result

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.

like image 93
Asya Kamsky Avatar answered Oct 20 '25 16:10

Asya Kamsky