In what year was the youngest bike rider from the sample_training.trips collection born?

In sample_training database (trips collection)
When I’m running query for this while sorting .sort({“birth year”:1}), i’m getting the exact value for loldest year but when i’m running it for .sort({“birth year”:-1}) I’m getting null value.

db.trips.find({“birth year”:{"$ne":null}},{“birth year”:1,"_id":0}).sort({“birth year”:1}).limit(1)

{ 'birth year': 1885 }

db.trips.find({“birth year”:{"$ne":null}},{“birth year”:1,"_id":0}).sort({“birth year”:-1}).limit(1)

{ 'birth year': '' }                //Error

What about filtering document that do not have a numeric birth year?

1 Like

Thanks, I noticed it later that it was an empty string and not null