I have a document that looks like this.
{
city: "Manhattan",
State: "NY",
eth:[
{02: 40},
{15:50},
{04:10}
]
}
What I wanna do is find the object within the eth array with the max value. I have tried doing this.
project:{
{'eth':{$reduce:{
input:"$eth",
initialValue:1,
in:{$max:["$$value","$$this"]}
}}}
,{
$project:{"eth":{$objectToArray:"$eth"}},
}
}
which results into [{k: 15, v:60}].
How do I get the value of k as my eth. I tried doing another project where I tried to get "$eth[0].k" but it results as undefined.
I want the output to look like :
{
city: "Manhattan",
state:"NY",
eth: 15
}