Details
-
Improvement
-
Status: Backlog
-
Major - P3
-
Resolution: Unresolved
-
None
-
None
-
None
-
Query Optimization
Description
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
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() );
|
Attachments
Issue Links
- is related to
-
SERVER-6864 positional operator projection inclusion can mess up array based non positional operator
-
- Closed
-
-
SERVER-43334 Disallow additional path components after the positional projection ("$") operator
-
- Closed
-