-
Type: Task
-
Resolution: Gone away
-
Priority: Unknown
-
None
-
Affects Version/s: None
-
Component/s: None
-
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.
- depends on
-
CDRIVER-2859 Add bson_decimal128_compare function
- Closed
- is related to
-
PHPC-2206 Implement MongoDB\BSON\Value class as wrapper for bson_value_t
- Closed