Suppose I have a document structure where one of the fields, X, is an array av objects as shown below.
"X" : [
{
"A" : "abc",
"B" : 123
},
{
"A" : "wer",
"B" : 124
},
{
"A" : "fgh",
"B" : 124
}
]
How can I project only the document where field B has the highest values? And if the maximum value is shared by several documents, I just want to return one of them (not important which one). In this case the result could look like:
"X" : [
{
"A" : "wer",
"B" : 124
}
]