I am trying to get the average of a whole field using the aggregation framework in Mongo. However i can\'t seem to find any example that uses it without a group parameter. <
First of all store numerical values as numbers. Afterwards you can use a simple statement to calculate the average:
db.collection.aggregate({
"$group": {
"_id": null,
"avg_bvc": { "$avg": "$bvc" }
}
})
You can simply use more $avg aggregation operators to get averages for your other numeric fields:
db.collection.aggregate({
"$group": {
"_id": null,
"avg_bvc": { "$avg": "$bvc" },
"avg_dollar": { "$avg": "$dollar" }
}
})