I have this data in mongodb:
[ { "rating": 4, "ceatedAt": ISODate("2016-08-08T15:32:41.262+0000") }, { "rating": 3, "createdAt": ISODate("2016-08-08T15:32:41.262+0000") }, { "rating": 3, "ceatedAt": ISODate("2016-07-01T15:32:41.262+0000") }, { "rating": 5, "createdAt": ISODate("2016-07-01T15:32:41.262+0000") } ]
I need to get the average rating for this particular day / month depending on the filter criteria. if the filter range for the date is less than a month, then it will be grouped per day. if the filter range for a date is more than a month, then it will be grouped per month.
Here is what i expect
[ { "average": 3.5, "ceatedAt": "2016-08-08", "month": "August" }, { "average": 4, "ceatedAt": 2016-07-01, "month": "July" } ]
How can i do this in mongodb?
source share