//Aggregation query for events to summarise the nodes by current state.
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 elementwill need this later for {the priority { $group $lookup: { _id from: {node: "$_id"events", state: "$states.state", stateful localField: "$statesstates.statefuleventid_down", }, totalforeignField: {$sum: 1}"_id", as: "_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.
...