Uploaded image for project: 'Documentation'
  1. Documentation
  2. DOCS-3241

Define sort order of BinData type in BSON Types reference

    • Type: Icon: Task Task
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • v1.3.5
    • Affects Version/s: None
    • Component/s: manual
    • Labels:

      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.

            Assignee:
            Unassigned Unassigned
            Reporter:
            matt.kangas Matt Kangas
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:
              9 years, 49 weeks, 6 days ago