-
Type: Improvement
-
Resolution: Done
-
Priority: Minor - P4
-
None
-
Affects Version/s: None
-
Component/s: Aggregation Framework
-
Query
Many accumulators ignore null-ish values, but $first/$last do not.
Observed behavior: If the first or last entry for a field is undefined, the $first / $last accumulator becomes undefined (the field is dropped).
Expected behavior: Potentially the first / last non undefined field could be chosen.
Test:
c = db.c; c.drop(); c.save( {} ); c.save( { a:1 } ); c.save( {} ); // The 'a' field of the first document is undefined, so no 'z' result. printjson( c.aggregate( { $group:{ _id:0, z:{ $first:'$a' } } } ) ); // The 'a' field of the last document is undefined, so no 'z' result. printjson( c.aggregate( { $group:{ _id:0, z:{ $last:'$a' } } } ) ); // The 'z' result is [1], the undefined values of the first and last documents are excluded. printjson( c.aggregate( { $group:{ _id:0, z:{ $push:'$a' } } } ) );
- related to
-
SERVER-6471 aggregation $min uses Value ordering to compare null and undefined values, does not exclude null and undefined values from consideration
- Closed