I have the following collection:
{
"_id" : ObjectId("52e7aa3ed3d55b9b01e23f34"),
"time" : mytime,
"type_instance" : "",
"values" : [0.23, 0.08, 0.06],
"types" : ["type0", "type1", "type2"]
}
I want to group by time to get the average of the values per index. The desired result would be something like:
{
"time" : mytime,
"values" : [avg 0, avg 1, avg 2],
"types" : ["type0", "type1", "type2"]
}
I tried to aggregate
collection.aggregate([
{ "$match": {'time': {"$gte": start}
}
}
,{ "$project": {
"time":"$time",
"values": "$values"
}
}
,{
"$group": {"_id": "$time", "avg": {avg:"$values[0]"}}
}
,{
"$sort": {"time": 1}
}
], function(err, data) {});
Off course this doesn't work, I can't use "$values[0]". Is there a way to do this?