I'm trying to create an aggregation pipeline in MongoDB Compass for the field city in one of my collections. This is what I have so far:
[{$unwind: {
path: '$city',
preserveNullAndEmptyArrays: true
}}, {$group: {
_id: null,
distinctCities: { $addToSet: '$city' }
}}]
How can I add the number of occurrences for each cities? I would like to have an array that consists of objects with city and count.