Aggregation query for events to summarise the events by the priority.
Takes all events after a certain time and which are not acknowledged
Firstly it groups by the event name and priority, and counts the amount of events
db.getCollection('events').aggregate([ { $match: { "time": { "$gte": 1577836800 }, "acknowledged": { "$eq": 0 } } }, { $group: { _id: { event: "$event", priority: "$priority" }, priorities: { $push: "$priority" }, total: { $sum: 1 } } }, { $group: { _id: "$_id.event", priorities: { $push: { priority: "$_id.priority", count: "$total" } }, } } ])