Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-6125

aggregation $sort cannot process heterogenous data types (asserts)

    • Type: Icon: Improvement Improvement
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.3.2
    • 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.

            Assignee:
            mathias@mongodb.com Mathias Stearn
            Reporter:
            aaron Aaron Staple
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: