[
{
"rating": 4,
"createdAt": ISODate("2016-08-08T15:32:41.262+0000")
},
{
"rating": 4,
"createdAt": ISODate("2016-08-08T15:32:41.262+0000")
},
{
"rating": 3,
"createdAt": ISODate("2016-07-01T15:32:41.262+0000")
},
{
"rating": 5,
"createdAt": ISODate("2016-07-01T15:32:41.262+0000")
}
]
This is my dataset.
I use this to get the month number.
[
{
"$project": {
"createdAtMonth": { "$month": "$createdAt" },
"rating": 1
}
},
{
"$group": {
"_id": "$createdAtMonth",
"average": { "$avg": "$rating" },
"month": { "$first": "$createdAtMonth" }
}
}
]
I need to get the start date of that month in timestamp. How can I do that?
Expected output:
[{
"_id": 8,
"average": 4,
"month": 8,
"time": 1469989800000
}, {
"_id": 7,
"average": 4,
"month": 7,
"time": 1467311400000
}]
date might not be correct in this output. but basis on the input, I should get two object, one for july and one for august