From d79c6006e4d5659e91ff102225b602b3c74da0c0 Mon Sep 17 00:00:00 2001 From: Eliot Horowitz Date: Mon, 2 Nov 2009 12:25:51 -0500 Subject: [PATCH] fix multi-update and modding indexed field SERVER-268 SERVER-108 --- db/update.cpp | 12 ++++++++++-- jstests/update7.js | 14 ++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/db/update.cpp b/db/update.cpp index 4026e560413f4..cc962edcfc0c8 100644 --- a/db/update.cpp +++ b/db/update.cpp @@ -734,7 +734,13 @@ namespace mongo { mods.getMods(updateobj); NamespaceDetailsTransient& ndt = NamespaceDetailsTransient::get(ns); set& 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; } diff --git a/jstests/update7.js b/jstests/update7.js index ee24ff02377fa..b893121080fe9 100644 --- a/jstests/update7.js +++ b/jstests/update7.js @@ -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" )