PyMongo aggregation no result

I am trying to query the average "clicks" from a MongoDB database using PyMongo.

query_result = list(my_collection.aggregate([{'$group' : {'_id' : None, 'avg_clicks': {'$avg' : "$clicks"}}}]))

      

Query result:

ok
result

      

Do you know what could be the problem?

+3


source to share


1 answer


Collection.aggregate

returns a dictionary like

{'ok': 1 or 0, 'result': the_actual_result}

      

Thus,



list(my_collection.aggregate(...))

      

iterates over the dictionary, getting a list of keys ['ok', 'result']

.

+3


source







All Articles