Getting the value of the most occurrences

Thanks for this, i will have a look .

I too though i needed to $unwind the downloads array, however the above is a trival example, and my real data has lots of other steps, including 2 other unwinds for nested array. Doesn’t this create a huge amount of workload and documents for mongodb atlas to process before sending data back? Granted i am not looking for best performance, but i did read this, pls scroll to the last comment made by a Mongo Employee (i think) [Asya_Kamsky]

Asha says that i should NOT, and she emphasized in capitals NOT. " You should never use $unwind and then $group when you just need to transform a single document! "

so thats why i went down the rabbit hole of .map and filter but still could not get the data i needed.

pls comment when you have a moment.

  • are so many unwinds bad
  • how far down can i do a projection expression i…e array.object.nestedArray.object… something like this wont work right? i would need to unwind it first?
    Since my downloads array isn’t nested, and i only want to reach in to downloads.country, why do i need a unwind here?

thanks.