[SERVER-7898] CLONE - don't allow mixing inclusion and exclusion in aggregation $project Created: 11/Dec/12  Updated: 11/Dec/12  Resolved: 11/Dec/12

Status: Closed
Project: Core Server
Component/s: Aggregation Framework
Affects Version/s: None
Fix Version/s: None

Type: Question Priority: Major - P3
Reporter: Vince Garcia Assignee: Mathias Stearn
Resolution: Incomplete Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Participants:

 Description   

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.



 Comments   
Comment by Vince Garcia [ 11/Dec/12 ]

Accidental Clone, sorry!

Generated at Thu Feb 08 03:15:54 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.