I have this collection in MongoDB. It contains values ββof different types under the key val.
Also, note that I sort it in ascending order of val.
[test] 2014-02-20 08:53:11.857 >>> db.account.find().sort({val:1}); { "_id" : ObjectId("5304d25786dd4b348bcc2b2e"), "username" : "usr10", "password" : "123", "val" : [ ] } { "_id" : ObjectId("5304d29986dd4b348bcc2b2f"), "username" : "usr20", "password" : "456", "val" : null } { "_id" : ObjectId("5304e31686dd4b348bcc2b37"), "username" : "usr80", "password" : "555", "val" : 1 } { "_id" : ObjectId("5304d50a86dd4b348bcc2b32"), "username" : "usr50", "password" : "555", "val" : [ 40 ] } { "_id" : ObjectId("5304d4c886dd4b348bcc2b31"), "username" : "usr40", "password" : "777", "val" : 200 } { "_id" : ObjectId("5304d2a186dd4b348bcc2b30"), "username" : "usr30", "password" : "888", "val" : { } } { "_id" : ObjectId("5304d97786dd4b348bcc2b33"), "username" : "usr50", "password" : "555", "val" : { "ok" : 1 } } { "_id" : ObjectId("5304e2dc86dd4b348bcc2b36"), "username" : "usr80", "password" : "555", "val" : true } { "_id" : ObjectId("5304e22f86dd4b348bcc2b34"), "username" : "usr60", "password" : "555", "val" : ISODate("2014-02-19T16:56:15.787Z") } { "_id" : ObjectId("5304e2c786dd4b348bcc2b35"), "username" : "usr70", "password" : "555", "val" : /abc/ } [test] 2014-02-20 08:53:19.357 >>>
I am reading a book that says the following.
MongoDB has a hierarchy regarding how types are mapped. Sometimes you will have one key with several types: for example, integers and booleans, or strings and nulls. If you do a sort by key with a mixed type, there is a predefined version for them to be sorted. Smallest to largest this order
is as follows:
1. The minimum value
2.null
3. Numbers (integers, long, double)
4. Rows
5. Object / document
6. Array
7. Binary data
8. Object identifier
9. Logical
10. Date
11. Timestamp
12. Regular expression
13. Maximum value
So why is my sort order different? For example, photos when I sort (see above), I see these strange things:
1) I have no idea what the "minimum value" and "maximum value" mean.
2) An array comes before a number. And an empty array comes before zero.
3) Number 1 in front of the array
4) Array [40] is between numbers 1 and 200.
Can someone just explain this result in some detail?
Thank you very much in advance.