0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-11-30 09:06:21 +01:00

fix upsert with addToSet SERVER-630

This commit is contained in:
Eliot Horowitz 2010-02-12 14:43:27 -05:00
parent 09454a9ef6
commit a023fc861b
3 changed files with 13 additions and 6 deletions

View File

@ -789,10 +789,7 @@ namespace mongo {
if ( upsert ) { if ( upsert ) {
if ( updateobj.firstElement().fieldName()[0] == '$' ) { if ( updateobj.firstElement().fieldName()[0] == '$' ) {
/* upsert of an $inc. build a default */ /* upsert of an $inc. build a default */
ModSet mods(updateobj); BSONObj newObj = mods->createNewFromQuery( patternOrig );
BSONObj newObj = mods.createNewFromQuery( patternOrig );
if ( profile ) if ( profile )
ss << " fastmodinsert "; ss << " fastmodinsert ";
theDataFileMgr.insert(ns, newObj); theDataFileMgr.insert(ns, newObj);

View File

@ -406,7 +406,8 @@ namespace mongo {
switch ( m.op ){ switch ( m.op ){
case Mod::PUSH: { case Mod::PUSH:
case Mod::ADDTOSET: {
BSONObjBuilder arr( b.subarrayStart( m.shortFieldName ) ); BSONObjBuilder arr( b.subarrayStart( m.shortFieldName ) );
arr.appendAs( m.elt, "0" ); arr.appendAs( m.elt, "0" );
arr.done(); arr.done();

View File

@ -1,5 +1,6 @@
t = db.update_addToSet1; t = db.update_addToSet1;
/*
t.drop(); t.drop();
o = { _id : 1 , a : [ 2 , 1 ] } o = { _id : 1 , a : [ 2 , 1 ] }
@ -13,7 +14,15 @@ assert.eq( o , t.findOne() , "A2" );
t.update( {} , { $addToSet : { a : 3 } } ); t.update( {} , { $addToSet : { a : 3 } } );
assert.eq( o , t.findOne() , "A3" ); assert.eq( o , t.findOne() , "A3" );
*/
// SERVER-628 // SERVER-628
// t.update( {} , { $addToSet : { a : { $each : [ 3 , 5 , 6 ] } } } ); // 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" );