Skip to content

Commit

Permalink
fix multi-update and modding indexed field SERVER-268 SERVER-108
Browse files Browse the repository at this point in the history
  • Loading branch information
erh committed Nov 2, 2009
1 parent 39645a2 commit d79c600
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
12 changes: 10 additions & 2 deletions db/update.cpp
Expand Up @@ -734,15 +734,21 @@ 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 )
ss << " fastmod ";
} 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 );
}
Expand All @@ -763,6 +769,8 @@ namespace mongo {
numModded++;
if ( ! multi )
break;
if ( multi && isIndexed )
c->checkLocation();
continue;
}

Expand Down
14 changes: 14 additions & 0 deletions jstests/update7.js
Expand Up @@ -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" )

0 comments on commit d79c600

Please sign in to comment.