|
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() );
|
|