twisted / txmongo

asynchronous python driver for mongo
https://txmongo.readthedocs.io
Apache License 2.0
338 stars 102 forks source link

Cursor support for aggregations #174

Open mikeiwi opened 8 years ago

mikeiwi commented 8 years ago

According to pymongo you can pass a kwarg parameter useCursor in an aggregate call so the returned value will be a cursor instead of a document with the whole query result. This seems to be not working with txmongo, I'm getting a aggregate() got an unexpected keyword argument 'useCursor' error.

This is a sample of the code I'm running:

coll.aggregate([{"$unwind": "$fieldName"}], full_response=False, useCursor=True)

I also checked the aggregate method in collection.py but couldn't find anything related to a cursor, only **kwargs (just like in pymongo), but they seem to be not working.

Am I missing something here maybe?, Thank you so much for your help.

trenton42 commented 8 years ago

@miketb24 A lot of the deep internals in txmongo (especially things that deal with IO, like cursors) are not directly compatible with pymongo. It is very difficult (if not impossible) to directly iterate over something in Twisted that depends on IO in the middle of a loop.

Perhaps the documentation should be more clear to point those differences out.

IlyaSkriblovsky commented 8 years ago

@miketb24 TxMongo doesn't have cursor support for aggregate for now. But patches are welcome :-)

IlyaSkriblovsky commented 8 years ago

Quick research on the topic showed that aggregate command with cursor:{} returns a document of different shape: it contains the cursor id (possibly 0) and the first batch of results. The solution would be to extract cursor consuming logic from find_with_cursor and use it in both find_with_cursor and aggregate.