I have a rudimentary at best understanding of MongoDB and aggregation. I have not been able to find a clear example of how one might compare multiple documents which match a criteria and return 1 document with the maximum value in a specific attribute.
Say we have the following documents in a collection:
{ name: "a" , value: 2 }
{ name: "a" , value: 4 }
{ name: "a" , value: 6 }
{ name: "b" , value: 2 }
{ name: "b" , value: 8 }
How would I filter by name
(eq("name","a")
) and then return the document with the highest value
?