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

Support dotted field past positional operator with positional operator projection

    • Type: Icon: Improvement Improvement
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Querying
    • None
    • Query Optimization

      With update the positional operator can be combined with additional fields after the dollar sign, for example 'a.$.b' to indicate the 'b' field within the matched array element. This is not yet supported with positional projections.

      Observed behavior: Projecting

      { 'a.$.b':1 }

      is equivalent to projecting

      { 'a.$':1 }

      .
      Expected behavior: Projecting

      { 'a.$.b':1 }

      will project only the 'b' field within the matching array element.

      Test

      c = db.c;
      c.drop();
      
      c.save( { a:[ { b:10, c:1 }, { b:5, c:1 } ] } );
      
      // Update the 'b' field within the matching array element.
      c.update( { 'a.b':5 }, { $set:{ 'a.$.b':6 } } );
      printjson( c.findOne() );
      
      // Projects the entire matching array element.
      printjson( c.find( { 'a.b':6 }, { 'a.$':1 } ).toArray() );
      
      // Projects the entire matching array element (contrary to expected behavior).
      printjson( c.find( { 'a.b':6 }, { 'a.$.b':1 } ).toArray() );
      
      // Projects the 'b' fields within all array elements.
      printjson( c.find( { 'a.b':6 }, { 'a.b':1 } ).toArray() );
      

            Assignee:
            backlog-query-optimization [DO NOT USE] Backlog - Query Optimization
            Reporter:
            aaron Aaron Staple
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated: