MongoDB semantics undefined versus zero in cursor.sort ()

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?

+4
source share
1 answer

( ), undefined . , , , null/undefined:

> db.sort2.find().sort({"a" : 1});
{ "_id" : ObjectId("526a4d45b4e29833675fb089"), "a" : null }
{ "_id" : ObjectId("526a4d4cb4e29833675fb08b") }
{ "_id" : ObjectId("526a4d48b4e29833675fb08a"), "a" : 21433 }
>
> db.sort2.find().sort({"a" : -1});
{ "_id" : ObjectId("526a4d48b4e29833675fb08a"), "a" : 21433 }
{ "_id" : ObjectId("526a4d45b4e29833675fb089"), "a" : null }
{ "_id" : ObjectId("526a4d4cb4e29833675fb08b") }

, a , (!). , . , , , -, .

null : null ( , ), .

+1

All Articles