I’m having some trouble understanding how to query a specific collection. The collection looks something like:
[{
"_id": {
"$oid": "625737ddbbd1522b17c6e1f8"
},
"server": "LS-FB1-P",
"check": "device offline",
"status": "Passed",
"comment": "No comment",
"timestamp": "2022-04-13 13:55",
"system": "Skynet"
},{
"_id": {
"$oid": "6261bf6a27866b323667e569"
},
"server": "LS-FB2-P",
"check": "device offline",
"status": "Failed",
"comment": "No comment",
"timestamp": "2022-04-13 14:55",
"system": "Skynet"
},{
"_id": {
"$oid": "6261bf7427866b323667e56a"
},
"server": "LS-FB11-P",
"check": "device offline",
"status": "Passed",
"comment": "No comment",
"timestamp": "2022-04-13 14:55",
"system": "Skynet"
},{
"_id": {
"$oid": "6261c18127866b323667e56b"
},
"server": "LS-FB1-P",
"check": "server offline",
"status": "Passed",
"comment": "No comment",
"timestamp": "2022-04-12 11:55",
"system": "Skynet"
},{
"_id": {
"$oid": "6261c18a27866b323667e56c"
},
"server": "LS-FB2-P",
"check": "server offline",
"status": "Passed",
"comment": "No comment",
"timestamp": "2022-04-13 14:55",
"system": "Skynet"
},{
"_id": {
"$oid": "6261c19127866b323667e56d"
},
"server": "LS-FB11-P",
"check": "server offline",
"status": "Passed",
"comment": "No comment",
"timestamp": "2022-04-13 14:55",
"system": "Skynet"
},{
"_id": {
"$oid": "62685c7f27866b323667e5e6"
},
"server": "LS-FB1-P",
"check": "device offline",
"status": "Passed",
"comment": "No comment",
"timestamp": "2022-04-14 13:55",
"system": "Skynet"
}]
This is to simulate some kind of logging where different checks are performed on different servers at some point in time. As you see the same server might appear multiple times for the same check, as the check can happen multiple times during the same day or a number of times over a number of days.
I want to query this data so that I only get all the servers and the different checks, but only the latest one for each server-check combination. I plan to use this data to create a matrix of servers and checks and show a pass/fail text dependant on the latest check results for each server-check combination.
Is there a way to make such a query in one go based on the structure of the collection?