The collection has fields like key,version,date and status. Same key can have multiple entries in the collection with a unique version, date and Status.
How can we write an aggregation to find all the documents with max version. For example - I have a sample collection created here - https://mongoplayground.net/p/nyAdYmzf59H
The expected output is
[{
"key": 1,
"version": 2,
"date": "Feb/10",
"status": "DRAFT"
}, {
"key": 2,
"version": 1,
"date": "March/10",
"status": "ACTIVE"
}, {
"key": 3,
"version": 3,
"date": "Jun/10",
"status": "DRAFT"
}
]