Details
-
Improvement
-
Resolution: Done
-
Minor - P4
-
None
-
None
-
Query
Description
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' } } } ) );
|
Attachments
Issue Links
- 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
-