Been trying to find the most occurences of a string.
I wanted to do this in a $addFields
Here is the playground, showing demo data, and my query so far.
This is my playground so far, but i feel its very messy.
I am using $map and $filter. I was told this was better then always using $unwind.
My expected output is
`{`
` name : 'steve',`
` TopCountry : HKG`
` }`
But presently it is showing me the total count.
{
name : 'steve',
TopCountry : 1
}`
I would also like to do a sort in the add fields, so it sorts it by top most occurences of country.
Maybe use of a $reduce would be better so i could reduce to the number of times a country was listed.
HKG : 4
USA : 3
CHN : 5
thanks.