-
Type: Bug
-
Resolution: Cannot Reproduce
-
Priority: Minor - P4
-
None
-
Affects Version/s: 3.4.16
-
Component/s: None
-
None
-
Environment:Linux x64
-
ALL
-
https://docs.mongodb.com/manual/reference/bson-type-comparison-order/#bindata
Says MongoDB sorts BinData in the following order:
.... Finally, by the data, performing a byte-by-byte comparison.
We had engineered this around the expectation that this order would compare the bytes in the raw data however we have discovered to our dismay that it appears to be comparing the Base64-encoded strings instead which is not the same order as comparing the bytes of the raw data.
Note that this this doesn't just apply to the shell; I was led to this conclusion when queries were not returning data I was expecting and assume I could demonstrate the same behavior with a server-side query as well.
This is actually a serious bug because it means you can't properly sequence binary data (like IPv6 addresses) in a way that supports range compares but I have no expectation that this will actually be fixed – I suspect instead that this will turn into a documentation bug that warns others off from using this datatype.