Old question, but still first google hit, so i post it here so i find it again more easily...
Using Mongo 4.2 and an aggregate():
db.collection.aggregate(
[
{ $match: { "end_time": { "$gt": ISODate("2020-01-01T00:00:00.000Z") } } },
{ $project: {
"end_day": { $dateFromParts: { 'year' : {$year:"$end_time"}, 'month' : {$month:"$end_time"}, 'day': {$dayOfMonth:"$end_time"}, 'hour' : 0 } }
}},
{$group:{
_id: "$end_day",
"count":{$sum:1},
}}
]
)
This one give you the groupby variable as a date, sometimes better to hande as the components itself.