I have a collection with documents like follows and I want to sort the documents with respect to the highest date value they contain in status array:
[{
"_id": "1",
"name": "Tea",
"status": [
{
"state": "a",
"date": "2019-08-22"
},
{
"state": "b",
"date": "2019-07-12"
},
],
"_id": "2",
"name": "Coffee",
"status": [
{
"state": "c",
"date": "2019-05-01"
},
{
"state": "b",
"date": "2019-12-31"
}
]
}]
So, in the example, the values to be used for sorting should be like:
- Tea: highest status date
2019-08-22(state: a) - Coffee: highest status date
2019-12-31(state: b)
Any ideas?