Mongo average aggregation query with no group
So if your data actually was numeric which is it not and your intention is to exclude the documents that have a "greater than zero" value then you include a $match
statement in your aggregation pipeline in order to "filter" out these documents:
db.EvaluatedSentiments.aggregate([
{ "$match": {
"bvc": { "$gt": 0 }
}},
{ "$group": {
"_id": null,
"bvc": { "$avg": "$bvc" }
}}
])
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" }
}
}])