|
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
|
|