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

aggregation $min uses Value ordering to compare null and undefined values, does not exclude null and undefined values from consideration

    • Type: Icon: Improvement Improvement
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.3.2
    • Affects Version/s: None
    • Component/s: Aggregation Framework
    • None
    • Minor Change

      Observed behavior: Undefined and null are considered less than other values and as a result the computed $min value of a field will be null or undefined if null or undefined values are present for that field.
      Expected behavior: We should specify some rules for operators to handle null and undefined. Perhaps null and undefined values should be excluded when calculating the min value.

      Test:

      > c.drop()
      true
      > c.save( { a:1 } )
      > c.save( { a:null } )
      > c.aggregate( { $group:{ _id:0, max:{ $max:'$a' }, min:{ $min:'$a' } } } )
      {
      	"result" : [
      		{
      			"_id" : 0,
      			"max" : 1,
      			"min" : null  // min is computed as null, not 1
      		}
      	],
      	"ok" : 1
      }
      > c.drop()
      true
      > c.save( { a:1 } )
      > c.save( {} )
      > c.aggregate( { $group:{ _id:0, max:{ $max:'$a' }, min:{ $min:'$a' } } } )
      { "result" : [ { "_id" : 0, "max" : 1 } ], "ok" : 1 } // min is 'undefined' so excluded from the result
      

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

              Created:
              Updated:
              Resolved: