0

I have a dataset that looks like:

[{ operation : 'save', created_at : '10-12-2016', count : 2},
 { operation : 'save', created_at : '16-12-2016' , count : 3},
 { operation : 'save', created_at : '21-12-2016' , count : 4}]

I want to calculate the average 'count' for the whole month, meaning include all the missing 0 values for each day of the month. Can I achive this using only the momgodb aggregation framework?

  • yeah you can first group by month refer to this link for grouping ->http://stackoverflow.com/questions/27366209/mongodb-group-by-month and then you can use $avg to find average ->https://docs.mongodb.com/manual/reference/operator/aggregation/avg/ – Riya Saxena Jan 10 '17 at 13:01
  • This will give me an avg of 3 (2+3+4 /3) and what I need is an avg of (0+0+0+...+0+2+0+...+3+...+0+4 /n) – Dok Umansky Jan 10 '17 at 13:12

0 Answers0