xaroulis gekas
xaroulis gekas

Reputation: 165

How to find $avg in mongodb query with python pymongo

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

Answers (1)

Belly Buster
Belly Buster

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

Related Questions