-
Type: Bug
-
Resolution: Won't Fix
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: Aggregation Framework
-
None
-
Query
-
Fully Compatible
-
ALL
An array in an input doc can cause unexpected behavior when $project-ing a computed value within an output field of the same name.
Test:
c = db.c; // Note the $sort stages are required so the document source cursor includes 'a' in its Project. c.drop(); c.save( { a:[ {}, {}, {} ], x:'bar' } ); printjson( c.aggregate( { $sort:{ a:1 } }, { $project:{ a:{ c:'$x' } } } ).toArray() ); c.drop(); c.save( { a:[ 1, 2, 3 ], x:'bar' } ); printjson( c.aggregate( { $sort:{ a:1 } }, { $project:{ a:{ c:'$x' } } } ).toArray() );
Output
Aaron-Staples-MacBook-Pro:mongo8 aaron$ ./mongo test.js MongoDB shell version: 2.2.0-rc1-pre- connecting to: test { "result" : [ { "_id" : ObjectId("501dc1a903c33b9898335417"), "a" : [ { "c" : "bar" }, { "c" : "bar" }, { "c" : "bar" } ] } ], "ok" : 1 } { "result" : [ { "_id" : ObjectId("501dc1a903c33b9898335418"), "a" : [ ] } ], "ok" : 1 }
Expected output:
Aaron-Staples-MacBook-Pro:mongo8 aaron$ ./mongo test.js MongoDB shell version: 2.2.0-rc1-pre- connecting to: test { "result" : [ { "_id" : ObjectId("501dc1d8aba874295f450cf6"), "a" : { "c" : "bar" } } ], "ok" : 1 } { "result" : [ { "_id" : ObjectId("501dc1d8aba874295f450cf7"), "a" : { "c" : "bar" } } ], "ok" : 1 }
- is related to
-
SERVER-18966 Allow exclusion in $project stage of aggregation pipeline
- Closed