[DOCS-11978] The documented BSON types sort order differs from the actual one Created: 21/Aug/18  Updated: 30/Oct/23

Status: Closed
Project: Documentation
Component/s: manual
Affects Version/s: None
Fix Version/s: Server_Docs_20231030

Type: Bug Priority: Major - P3
Reporter: Dmitry Irlyanov Assignee: Unassigned
Resolution: Won't Do Votes: 0
Labels: bson, sort
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

https://docs.mongodb.com/manual/reference/bson-type-comparison-order/#bson-types-comparison-order


Participants:
Days since reply: 1 year, 14 weeks, 2 days ago
Epic Link: DOCSP-1769
Story Points: 0.2

 Description   

----------------------------

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:

  1. MinKey (internal type)
  2. Null
  3. Numbers (ints, longs, doubles, decimals)
  4. Symbol, String
  5. Object
  6. Array
  7. BinData
  8. ObjectId
  9. Boolean
  10. Date
  11. Timestamp
  12. Regular Expression
  13. 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)



 Comments   
Comment by Education Bot [ 31/Oct/22 ]

Hello! This ticket has been closed due to inactivity. If you believe this ticket is still important, please reopen it and leave a comment to explain why. Thank you!

Generated at Thu Feb 08 08:04:06 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.