-
Type: Question
-
Resolution: Done
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: Aggregation Framework
-
None
Observed behavior: When a subfield is excluded, its parent field(s) will be included even if they would have otherwise been excluded.
Expected behavior: tbd, but with a find() projection an assertion is currently raised in this case.
c = db.c; c.drop(); c.save( { x:1, a:{b:1,c:1} } ); c.save( { x:1, a:{c:1} } ); // No 'a' field is included. printjson( c.aggregate( { $project:{ 'x':1 } } ) ); // The 'a' field is implicitly included due to the implementation of 'a.b' being excluded. printjson( c.aggregate( { $project:{ 'x':1, 'a.b':0 } } ) ); // An assertion is raised because one field is included and another is excluded. printjson( c.find( {}, { 'x':1, 'a.b':0 } ).toArray() );
Another effect of this behavior is that you cannot exclude both a field and its parent. So following on the above example you can't { $project:
{ a:0, 'a.b':0 }}. A human probably wouldn't write a projection like this, but a computer might.