Uploaded image for project: 'PHP Driver: Extension'
  1. PHP Driver: Extension
  2. PHPC-2209

Make BSON\Value instances comparable

    • Type: Icon: Task Task
    • Resolution: Gone away
    • Priority: Icon: Unknown Unknown
    • None
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None

      The MongoDB\BSON\Value class does not implement a comparison handler, as there is no simple way to compare BSON values of different types. This most likely needs a bson_value_compare handler in libmongoc, which would also require a way to compare decimal128 values, along with ensuring that numbers of different types compare correctly (i.e. comparing 3 as an int32 with 3 as int64 should return them as equal).

      Note that bson_compare only does a memory comparison up to the length of the shorter BSON document. This also prohibits us from using a workaround (by embedding a bson_value_t in a bson_t and calling bson_compare on it), as it doesn't follow the procedures above either.

      A first step would be to employ something similar for bson_value_t: when comparing values of different types, return a consistent order (e.g. by returning a.value_type <=> b.value_type). If the type is equal, use memcmp to compare contents and ensure a consistent ordering.

      A complete solution would define comparison rules for all types, ensuring that numbers of different types are treated accordingly. This would also entail re-using the order defined above to ensure consistent results. For example, if a < b is true, b >= a also must be true.

            Assignee:
            Unassigned Unassigned
            Reporter:
            andreas.braun@mongodb.com Andreas Braun
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: