I'm new in Python and MongoDB and I am starting a new project with flask-python and MongoDB. When I try returning data using the aggregate()
function, it gives me the following error:
command cursor' object is not subscriptable.
Here is my code for the query:
Data = db.mytable.aggregate([ { "$group": {"_id": "$Name" ,"count": { "$sum": 1 }}}])
return Data['result']
I also changed this:
Data = db.mytable.aggregate([ { "$group": {"_id": "$Name" ,"count": { "$sum": 1 }}}],userCursor= False)
but it gives me the following error:
error.pymongo.errors.OperationFailure: command SON([('aggregate', 'mytable'), ('pipeline', [{'$group': {'_id': '$Name', 'count': {'$sum': 1}}}]), ('useCursor', False)]) on namespace mydb.$cmd failed: unrecognized field 'useCursor
Note: I am using MongoDB 3.2 and Python3