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

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.3.2
    • Component/s: Aggregation Framework
    • Labels:
      None
    • Backwards Compatibility:
      Minor Change

      Description

      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

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                1 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: