Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-6175

don't allow mixing inclusion and exclusion in aggregation $project

    • Type: Icon: Question Question
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.2.0
    • 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.

            Assignee:
            mathias@mongodb.com Mathias Stearn
            Reporter:
            aaron Aaron Staple
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: