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

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

    XMLWordPrintableJSON

Details

    • Icon: Question Question
    • Resolution: Incomplete
    • Icon: Major - P3 Major - P3
    • None
    • None
    • Aggregation Framework
    • None

    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.

      Attachments

        Activity

          People

            mathias@mongodb.com Mathias Stearn
            vincetg2 Vince Garcia
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: