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

Define sort order of BinData type in BSON Types reference

    XMLWordPrintableJSON

Details

    • Icon: Improvement Improvement
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • v1.3.5
    • None
    • manual

    Description

      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.

      Attachments

        Activity

          People

            tim.slavin Tim Slavin
            matt.kangas Matt Kangas
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

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