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:
parent
09454a9ef6
commit
a023fc861b
@ -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);
|
||||
|
@ -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();
|
||||
|
@ -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" );
|
||||
|
Loading…
Reference in New Issue
Block a user