According to the information in the manoDB manpage on cursor.sort (the last paragraph on comparing values), NULL values are less than any other values in the members of the sort () function.
The question is, are there no attributes considered to be NULL? In my tests, not so:
> db.sort.find().sort({id:1})
{ "_id" : ObjectId("5269554df18e7d2f4bd1241d"), "a" : "Anonym" }
{ "_id" : ObjectId("52695684f18e7d2f4bd12421"), "a" : "Bnonym", "d" : "iii" }
{ "_id" : ObjectId("52695892f18e7d2f4bd12422"), "id" : null, "a" : "Bnonym", "d" : "iii" }
{ "_id" : ObjectId("5269591bf18e7d2f4bd12425"), "id" : null, "a" : "ZZZaaa", "d" : "iii" }
{ "_id" : ObjectId("526954d4f18e7d2f4bd1241b"), "id" : 7, "a" : "Jozo" }
The order looks like this:
- undefined / missing sort attribute
- null value
- the rest in the order from the manpage
Q: Question: is there any non-documented type other than zero for missing attributes under the hood?
source
share