diff --git a/db/update.cpp b/db/update.cpp index d5f05d64e27..f1038d408f6 100644 --- a/db/update.cpp +++ b/db/update.cpp @@ -789,10 +789,7 @@ namespace mongo { if ( upsert ) { if ( updateobj.firstElement().fieldName()[0] == '$' ) { /* upsert of an $inc. build a default */ - ModSet mods(updateobj); - - BSONObj newObj = mods.createNewFromQuery( patternOrig ); - + BSONObj newObj = mods->createNewFromQuery( patternOrig ); if ( profile ) ss << " fastmodinsert "; theDataFileMgr.insert(ns, newObj); diff --git a/db/update.h b/db/update.h index d3b4f7008b9..811702593bf 100644 --- a/db/update.h +++ b/db/update.h @@ -406,7 +406,8 @@ namespace mongo { switch ( m.op ){ - case Mod::PUSH: { + case Mod::PUSH: + case Mod::ADDTOSET: { BSONObjBuilder arr( b.subarrayStart( m.shortFieldName ) ); arr.appendAs( m.elt, "0" ); arr.done(); diff --git a/jstests/update_addToSet.js b/jstests/update_addToSet.js index 07c44ee2462..72dfe0334c0 100644 --- a/jstests/update_addToSet.js +++ b/jstests/update_addToSet.js @@ -1,5 +1,6 @@ t = db.update_addToSet1; +/* t.drop(); o = { _id : 1 , a : [ 2 , 1 ] } @@ -13,7 +14,15 @@ assert.eq( o , t.findOne() , "A2" ); t.update( {} , { $addToSet : { a : 3 } } ); assert.eq( o , t.findOne() , "A3" ); - +*/ // SERVER-628 // t.update( {} , { $addToSet : { a : { $each : [ 3 , 5 , 6 ] } } } ); + + + +// SERVER-630 +t.drop(); +t.update( { _id : 2 } , { $addToSet : { a : 3 } } , true ); +assert.eq( 1 , t.count() , "B1" ); +assert.eq( { _id : 2 , a : [ 3 ] } , t.findOne() , "B2" );