Permalink
Browse files

SERVER-5067 Explicitly request elemMatchKey for update operations wit…

…h a dynamic array, forcing a full record load on a positive match.
  • Loading branch information...
1 parent 708047a commit bae4737b585f3e32b893e26dbe65e3e61947a76d @astaple astaple committed Mar 17, 2012
Showing with 27 additions and 0 deletions.
  1. +19 −0 jstests/update_arraymatch7.js
  2. +8 −0 src/mongo/db/ops/update.cpp
@@ -0,0 +1,19 @@
+// Check that the positional operator works properly when an index only match is used for the update
+// query spec. SERVER-5067
+
+t = db.jstests_update_arraymatch7;
+t.drop();
+
+function testPositionalInc() {
+ t.remove();
+ t.save( { a:[ { b:'match', count:0 } ] } );
+ t.update( { 'a.b':'match' }, { $inc:{ 'a.$.count':1 } } );
+ // Check that the positional $inc succeeded.
+ assert( t.findOne( { 'a.count':1 } ) );
+}
+
+testPositionalInc();
+
+// Now check with a non multikey index.
+t.ensureIndex( { 'a.b' : 1 } );
+testPositionalInc();
@@ -1116,6 +1116,14 @@ namespace mongo {
debug.nscanned++;
+ if ( mods.get() && mods->hasDynamicArray() ) {
+ // The Cursor must have a Matcher to record an elemMatchKey. But currently
+ // a modifier on a dynamic array field may be applied even if there is no
+ // elemMatchKey, so a matcher cannot be required.
+ //verify( 16098, c->matcher() );
+ details.requestElemMatchKey();
+ }
+
if ( !c->currentMatches( &details ) ) {
c->advance();

0 comments on commit bae4737

Please sign in to comment.