Uploaded image for project: 'Ruby Driver'
  1. Ruby Driver
  2. RUBY-3533

BSON Binary incompatible with Ruby standard lib sorting like SortedSet

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • bson-5.0.2
    • Affects Version/s: None
    • Component/s: BSON
    • None
    • Fully Compatible
    • Ruby Drivers
    • Needed
    • Hide

      1. What would you like to communicate to the user about this feature?

      BSON::Binary instances are now comparable, and sortable.

      2. Would you like the user to see examples of the syntax and/or executable code and its output?

      Not necessary.

      3. Which versions of the driver/connector does this apply to?

      This will be introduced with the release of bson-ruby 5.0.2.

      Show
      1. What would you like to communicate to the user about this feature? BSON::Binary instances are now comparable, and sortable. 2. Would you like the user to see examples of the syntax and/or executable code and its output? Not necessary. 3. Which versions of the driver/connector does this apply to? This will be introduced with the release of bson-ruby 5.0.2.

      Using Ruby BSON gem, release `bson (5.0.0)`.   The BSON::Binary class is not compatible with Ruby's native sorting implementation.  This can be seen with the `SortedSet` and simple `Array` Ruby classes.

      Binary data is completely sortable.  This is especially true for Binary Data that encodes UUIDs, which is what we are desire for our specific use case. 

      Example:

      ```

      ss = SortedSet[]
      bb1 = BSON::Binary.from_uuid(SecureRandom.uuid, :standard)
      bb2 = BSON::Binary.from_uuid(SecureRandom.uuid, :standard)

      1. The first add performs no comparisons, so it succeeds.
        ss.add(bb1)
      1. The second add call compares, and fails.
        ss.add(bb2)

      (irb):13:in `<main>': comparison of BSON::Binary with BSON::Binary failed (ArgumentError)

       

          @hash[o] = true

                ^^^^^^^^^

      1. The same thing happens with arrays:
        a1 = [bb1, bb2]
        a1.sort

      (irb):18:in `sort': comparison of BSON::Binary with BSON::Binary failed (ArgumentError)

      from (irb):18:in `<main>'

      ```

            Assignee:
            jamis.buck@mongodb.com Jamis Buck
            Reporter:
            adam.hampton@sailpoint.com Adam Hampton
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: