Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PyMongo aggregation no result

I try to query the average of 'clicks' from MongoDB database using PyMongo.

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

The result of the query is:

ok
result

Do you know what can be the problem?

like image 353
barnabas markus Avatar asked Jan 24 '26 00:01

barnabas markus


1 Answers

Collection.aggregate returns a dictionary like

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

Thus

list(my_collection.aggregate(...))

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

like image 159
vaultah Avatar answered Jan 26 '26 14:01

vaultah



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!