I am trying to group by DayHours in a mongo aggregate function to get the past 24 hours of data. For example: if the time of an event was 6:00 Friday the "DayHour" would be 6-5. I'm easily able to group by hour with the following query:
db.api_log.aggregate([
{ '$group': {
'_id': {
'$hour': '$time'
},
'count': {
'$sum':1
}
}
},
{ '$sort' : { '_id': -1 } }
])
I feel like there is a better way to do this. I've tried concatenation in the $project statement, however you can only concatenate strings in mongo(apparently). I effectively just need to end up grouping by day and hour, however it gets done. Thank You.