[SERVER-6175] don't allow mixing inclusion and exclusion in aggregation $project Created: 22/Jun/12  Updated: 11/Jul/16  Resolved: 17/Sep/13

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

Type: Question Priority: Major - P3
Reporter: Aaron Staple Assignee: Mathias Stearn
Resolution: Done 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 Andy Schwerin [ 08/Mar/13 ]

redbeard0531, is exclusion still forbidden in aggregation in 2.4?

Comment by Mathias Stearn [ 10/Jul/12 ]

SERVER-6361 handles this for 2.2

Comment by auto [ 10/Jul/12 ]

Author:

{u'date': u'2012-07-05T12:49:54-07:00', u'email': u'mathias@10gen.com', u'name': u'Mathias Stearn'}

Message: Clean up parseObject() a bit

prep for SERVER-6175
Branch: master
https://github.com/mongodb/mongo/commit/6db23108b65870f654e9dc612cc9b2bbc9891b63

Comment by auto [ 10/Jul/12 ]

Author:

{u'date': u'2012-07-05T12:07:09-07:00', u'name': u'Mathias Stearn', u'email': u'mathias@10gen.com'}

Message: Clean up DocumentSourceProject::createFromBson and make it more like normal projections

Prep for SERVER-6175
Branch: master
https://github.com/mongodb/mongo/commit/e9d9704e00c1c669a5bd078c2e33720a9f936017

Comment by Mathias Stearn [ 03/Jul/12 ]

For now I think we should adopt the same rule as the existing projections: you can't mix inclusion and exclusion (except for _id). The initial reason for that is that we couldn't come up with good semantics for mixing, and I haven't heard a good plan for that yet.

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