...
Code Block | ||
---|---|---|
| ||
db.getCollection('nodes').aggregate([ //get all nodes from the group HQDEV { $match: { group: "HQDev" } }, //Get all the states for the matched nodes { $lookup: { from: "state", localField: "_id", foreignField: "node", as: "states" } }, //unwinds the states array creating a document per state with node config data { $unwind: { path: "$states" } }, //We only want open states { $match: { 'states.state': { $eq: 'open' } } }, //Join group bywith the node,event thewhich statecreated andthis thestate, statefulwe element will need this later { for the priority { $group $lookup: { _id : {node from: "$_idevents", state localField: "$statesstates.stateeventid_down", stateful foreignField: "$states.stateful" }_id", total: {$sumas: 1} "_event" } }, //Then group by the node, and collectingaccumlate allits the states for the node { $group : { _id : "$_id.node", states: { $push: { state: "$_id$states.state", stateful: "$_id$states.stateful", countpriority: "$total$_event.priority" } } } }, ]) |
Aggregation query for events to summarise the events by the priority.
...