I have a collection of errors, so that every error carries a date field. How can I aggregate/count/group the errors by DAY only (i.e. exclude the time of the da
You can convert your timestamp field to string with specific date format by using $project (aggregation)
aggregate([
{
'$project': {
newFieldName: {'$dateToString': {format: '%Y-%m-%d', date: '$yourDateFieldName'}}
}
}, {
'$group': {
_id: {newFieldName: '$newFieldName'},
viewCount: {'$sum': 1}
}
},
{'$sort': {'_id.newFieldName': 1}}
], {})