barnabas markus
barnabas markus

Reputation: 61

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?

Upvotes: 3

Views: 793

Answers (1)

vaultah
vaultah

Reputation: 46593

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'].

Upvotes: 3

Related Questions