@kunokdev your solution is pretty straight forward, add $sum: 1 to get the count of each city_code, then $unwind the array, then sort by the count, then group and use $first. It will end up being 4 stages if it's playing out in my head correctly.

@kunokdev I'm actually working on some node.js code in ssh at the moment that pulls 2.6 million documents from mysql and then does 2.6 million upserts into mongodb. I'm having issues with the bulk statement I'm pretty sure due to the nodejs driver :(

when I just got started with all these stuff I met that sysadmin who was shell geek, he taught me so much stuff, and I learned a bit of shell over time and just with a small knowledge I could do more than ever before with regular programmer mindset

too bad guy got fired, now I am alone into this with windows-only users who dont even know what terminal is