Boleh dicoba,
- Kelompokkan menurut minggu
db.collection.aggregate([
{
$group: {
_id: {
year: { $year: "$createdAt" },
week: { $week: "$createdAt" }
},
createdAt: { $first: "$createdAt" },
count: { $sum: 1 }
}
}
])
- Kelompokkan menurut bulan
db.collection.aggregate([
{
$group: {
_id: {
year: { $year: "$createdAt" },
month: { $month: "$createdAt" }
},
createdAt: { $first: "$createdAt" },
count: { $sum: 1 }
}
}
])
- Kelompokkan menurut tahun
db.collection.aggregate([
{
$group: {
_id: { $year: "$createdAt" },
createdAt: { $first: "$createdAt" },
count: { $sum: 1 }
}
}
])