Reputation: 165
I am having hard time finding $avg in a mongodb query: The code i have used look like this:
cursor = mydb1.mongodbtime.aggregate({ "$avg": "$id13"})
Output:pipeline must be a list
I dont know how to fix it.
Upvotes: 1
Views: 1341
Reputation: 8844
All aggregate queries must be passed as lists in pymongo, and any aggregation must be part of a group or projection. Try this:
cursor = mydb1.mongodbtime.aggregate([{
'$group': {
'_id': 0,
'avg_id13': {'$avg': '$id13'}
}}])
Upvotes: 1