db.simulations.aggregate([
{
$group: {
_id: {
year: { $year: '$createdAt' },
month: { $month: '$createdAt' }
},
count: { $sum: 1 }
}
},
{
$project: {
_id: 0,
year: '$_id.year',
month: '$_id.month',
count: 1
}
},
{
$sort: {
year: 1,
month: 1
}
}
]);