|
----------------------------
Original Description
The comparison/sort order documentation (https://docs.mongodb.com/manual/reference/bson-type-comparison-order/#bson-types-comparison-order) provides the following sort order of BSON types:
- MinKey (internal type)
- Null
- Numbers (ints, longs, doubles, decimals)
- Symbol, String
- Object
- Array
- BinData
- ObjectId
- Boolean
- Date
- Timestamp
- Regular Expression
- MaxKey (internal type)
However at least for object and array types the sort order is different:
If create 2 objects:
db.test.insertOne({"key" : { "key" : "value" } })
|
db.test.insertOne({"key" : [ "value", "value" ]})
|
And perform sorting via cursor or aggregate the sort order will be different:
db.test.find().sort({"key":1})
|
{ "_id" : ObjectId("5b7c585ee9aa2bf28b64c184"), "key" : [ "value", "value" ] }
|
{ "_id" : ObjectId("5b7c553c431906bbc5028804"), "key" : { "key" : "value" } }
|
db.test.aggregate([{"$sort":{"key":1}}])
|
{ "_id" : ObjectId("5b7c585ee9aa2bf28b64c184"), "key" : [ "value", "value" ] }
|
{ "_id" : ObjectId("5b7c553c431906bbc5028804"), "key" : { "key" : "value" } }
|
NB: in Mongo 3.4.10 the output will be different: cursor sort will return object first.
----------------------------
Description
Scope of changes (files that need work and how much)
Impact to other docs outside of this product
MVP (work and date?)
Resources (e.g. Scope Docs, Invision)
|