In neither the BSON 1.0 spec nor the MongoDB BSON Types Reference do we document the index sort order of BinData.
We probably should include it in the MongoDB documentation since it is an important implementation detail. The actual sort order is:
- First compare length
- Then compare the one-byte subtype
- Then compare the content byte-by byte
It's defined in bson/bson-inl.h and db/pipeline/value.cpp
The fact that size is compared first is surprising to some. See https://github.com/mongodb/mongo/pull/666, SERVER-3260, SERVER-9925 for related discussions.
- is duplicated by
-
SERVER-13697 Document indexing and/or ordering for bindata
- Closed