Let's say I have a collection like this :
{_id: 1, value: 3, color: "white"}
{_id: 2, value: 5, color: "green"}
{_id: 3, value: 1, color: "white"}
{_id: 4, value: 2, color: "blue"}
{_id: 5, value: 4, color: "green"}
Is it possible to get the item with the highest value for each color ?
The expected output with our example would be :
{_id: 1, value: 3, color: "white"}
{_id: 2, value: 5, color: "green"}
{_id: 4, value: 2, color: "blue"}
The goal is to achieve this result in a single MongoDB request.