Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fix multi-update and modding indexed field SERVER-268 SERVER-108

  • Loading branch information...
commit d79c6006e4d5659e91ff102225b602b3c74da0c0 1 parent 39645a2
Eliot Horowitz erh authored
Showing with 24 additions and 2 deletions.
  1. +10 −2 db/update.cpp
  2. +14 −0 jstests/update7.js
12 db/update.cpp
View
@@ -734,7 +734,13 @@ namespace mongo {
mods.getMods(updateobj);
NamespaceDetailsTransient& ndt = NamespaceDetailsTransient::get(ns);
set<string>& idxKeys = ndt.indexKeys();
- if ( ! mods.isIndexed( idxKeys ) && mods.canApplyInPlaceAndVerify( loc.obj() ) ) {
+ bool isIndexed = mods.isIndexed( idxKeys );
+
+ if ( isIndexed && multi ){
+ c->noteLocation();
+ }
+
+ if ( ! isIndexed && mods.canApplyInPlaceAndVerify( loc.obj() ) ) {
mods.applyModsInPlace( loc.obj() );
//seenObjects.insert( loc );
if ( profile )
@@ -742,7 +748,7 @@ namespace mongo {
} else {
BSONObj newObj = mods.createNewFromMods( loc.obj() );
DiskLoc newLoc = theDataFileMgr.update(ns, r, loc , newObj.objdata(), newObj.objsize(), ss);
- if ( newLoc != loc ){
+ if ( newLoc != loc || isIndexed ){
// object moved, need to make sure we don' get again
seenObjects.insert( newLoc );
}
@@ -763,6 +769,8 @@ namespace mongo {
numModded++;
if ( ! multi )
break;
+ if ( multi && isIndexed )
+ c->checkLocation();
continue;
}
14 jstests/update7.js
View
@@ -122,3 +122,17 @@ assert.eq( "5,8,1,,,,,1" , s() , "E4" );
t.update( {} , { $inc : { x : 1 } } , false , true );
assert.eq( "6,9,2,1,1,1,1,2" , s() , "E5" );
+
+// --- $inc indexed field
+
+t.drop();
+
+t.save( { x : 1 } );
+t.save( { x : 2 } );
+t.save( { x : 3 } );
+
+t.ensureIndex( { x : 1 } );
+
+assert.eq( "1,2,3" , s() , "F1" )
+t.update( { x : { $gt : 0 } } , { $inc : { x : 5 } } , false , true );
+assert.eq( "6,7,8" , s() , "F1" )
Please sign in to comment.
Something went wrong with that request. Please try again.