Chapter 4: Core Aggregation $sortByCount

At 5:24, I’ve noticed that the output also computes the sum for null _id :

The $match at 4:52 could be something like this :

$match: { ‘offices.city’: { $exists: true, $ne: ‘’ }},

so null entries are not counted. Correct ?

@Laurent_Roger you are correct if you only want the documents having a city name, lets say, for a report on the cities, so it does not make sense having a record with a null name.

But for a person in charge of maintaining the data in the database clean and meaningful these output is very helpful, it is telling that there are 23 records (documents) in the collection not having the city name so there is an urgent need to check what went wrong

Jaime :space_invader: :coconut:

1 Like