diff options
author | Eliot Horowitz <eliot@10gen.com> | 2010-09-27 17:04:15 -0400 |
---|---|---|
committer | Eliot Horowitz <eliot@10gen.com> | 2010-09-27 17:04:40 -0400 |
commit | bde74e641390db642e6a81d4ca701081eac4f1fd (patch) | |
tree | 95fe1269b7aa06fd3332cdbe6c5d8bc6bb0c903a | |
parent | f1afbf0f4e52d0b4fc487d41b1c8bc8743d89092 (diff) | |
download | mongo-bde74e641390db642e6a81d4ca701081eac4f1fd.tar.gz |
don't sort incoming arrays for $addToSet/each SERVER-1863
-rw-r--r-- | db/update.cpp | 9 | ||||
-rw-r--r-- | jstests/update_addToSet3.js | 15 |
2 files changed, 22 insertions, 2 deletions
diff --git a/db/update.cpp b/db/update.cpp index a59387d860e..f2b05973db9 100644 --- a/db/update.cpp +++ b/db/update.cpp @@ -139,8 +139,13 @@ namespace mongo { toadd.erase( cur ); } - for ( BSONElementSet::iterator j=toadd.begin(); j!=toadd.end(); j++ ){ - bb.appendAs( *j , BSONObjBuilder::numStr( n++ ) ); + { + BSONObjIterator i( getEach() ); + while ( i.more() ){ + BSONElement e = i.next(); + if ( toadd.count(e) ) + bb.appendAs( e , BSONObjBuilder::numStr( n++ ) ); + } } } diff --git a/jstests/update_addToSet3.js b/jstests/update_addToSet3.js new file mode 100644 index 00000000000..77e5768e74b --- /dev/null +++ b/jstests/update_addToSet3.js @@ -0,0 +1,15 @@ + +t = db.update_addToSet3 +t.drop() + +t.insert( { _id : 1 } ) + +t.update( { _id : 1 } , { $addToSet : { a : { $each : [ 6 , 5 , 4 ] } } } ) +assert.eq( t.findOne() , { _id : 1 , a : [ 6 , 5 , 4 ] } , "A1" ) + +t.update( { _id : 1 } , { $addToSet : { a : { $each : [ 3 , 2 , 1 ] } } } ) +assert.eq( t.findOne() , { _id : 1 , a : [ 6 , 5 , 4 , 3 , 2 , 1 ] } , "A2" ) + +t.update( { _id : 1 } , { $addToSet : { a : { $each : [ 4 , 7 , 9 , 2 ] } } } ) +assert.eq( t.findOne() , { _id : 1 , a : [ 6 , 5 , 4 , 3 , 2 , 1 , 7 , 9 ] } , "A3" ) + |