-
Type: Improvement
-
Resolution: Done
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: Aggregation Framework
-
None
-
Fully Compatible
Value::compare does not compare heterogenous data types (however the different numeric types can be compared).
In particular this can cause issues if a value may or may not be within an array (even if it's a nested field).
// CW TODO for now, only compare like values uassert(16016, str::stream() << "can't compare values of BSON types " << lType << " and " << rType, lType == rType);
This can cause assertions when trying to $sort different data types for example:
c = db.c;
c.drop();
c.save( { a:1 } );
c.save( { a:true } );
printjson( c.aggregate( { $sort:{ a:1 } } ) );
And in particular it can also cause problems when some fields are within arrays (even nested):
c = db.c;
c.drop();
c.save( { a:{ b:1 } } );
c.save( { a:[ { b:2 } ] } );
printjson( c.aggregate( { $sort:{ 'a.b':1 } } ) );
Observed behavior: An assertion is raised when an attempt is made to sort a field containing different data types in different documents.
Expected behavior: The results are sorted, without an assertion, in spite of the different data types.
- is related to
-
SERVER-6206 need a policy for incompatible types in operators in aggregation expressions
- Closed