Hello,
I don’t seem to be able to figure out how to construct an aggregation to group by, then sort and then take one record from each group which is the latest added one.
Here is what my collection looks like:
{
"thresholds": [
{"name": "A", "violations": "0", "notes": "No violations detected"},
{"name": "B", "violations": "2", "notes": "Some info on detected violations goes here"},
{"name": "C", "violations": "1", "notes": "Some info on detected violations goes here"},
]
}
Then 3 more records are added and I get this:
{
"thresholds": [
{"name": "A", "violations": "0", "notes": "No violations detected"},
{"name": "B", "violations": "2", "notes": "Some info on detected violations goes here"},
{"name": "C", "violations": "1", "notes": "Some info on detected violations goes here"},
{"name": "A", "violations": "4", "notes": "Some details"},
{"name": "B", "violations": "3", "notes": "Some info on detected violations goes here"},
{"name": "C", "violations": "0", "notes": "All good"},
]
}
What I need the aggregation to return is the most recent added record for each group; i.e. “name”
Thanks in advance.