Details
-
Improvement
-
Resolution: Done
-
Major - P3
-
None
-
None
-
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
- is related to
-
SERVER-6199 $first and $last accumulators accept null, missing and undefined
-
- Closed
-
- related to
-
DOCS-974 Document new aggregation $min behavior in 2.4 of skipping null and undefined values
-
- Closed
-