i new mongodb. want take average, max, min document value in whole collection. able calculate max , min don't know how calculate average or how start it.
this how calculated max.
db.mytable.find({},{"abc":1}).sort({"abc":-1}).limit(1);
to average whole collection, use aggregation framework $group pipeline operator can specify _id value of null calculate accumulated average value input documents whole:
db.mytable.aggregate([ { "$group": { "_id": null, "avg": { "$avg": "$abc" } } } ]);
Comments
Post a Comment