I am stuck with achieving weekofMonth
instead of WeekofYear
. Can somebody guide me on how to get this right?
db.activity.aggregate([
{
$group:{
_id: {
week: { $week: "$createdAt" },
month: { $month: "$createdAt" },
year: { $year: "$createdAt" }
},
count: { $sum: 1 }
}
},
{ $match : { "_id.year" : 2016, "_id.month" : 5 } }
])
Output
/* 1 */
{
"_id" : {
"week" : 19,
"month" : 5,
"year" : 2016
},
"count" : 133.0
}
/* 2 */
{
"_id" : {
"week" : 18,
"month" : 5,
"year" : 2016
},
"count" : 1.0
}
In the above shown data, it is actually not displaying weekofMonth
. How can I get this given week 18 is the first week of Month?