Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fix case where the same element is in $each part of $addToSet SERVER-…

…2249
  • Loading branch information...
commit aed49ae7154431ed505eadc9706e41513209ca7a 1 parent 5276c00
Eliot Horowitz erh authored
4 db/update.cpp
View
@@ -155,8 +155,10 @@ namespace mongo {
BSONObjIterator i( getEach() );
while ( i.more() ){
BSONElement e = i.next();
- if ( toadd.count(e) )
+ if ( toadd.count(e) ){
bb.appendAs( e , BSONObjBuilder::numStr( n++ ) );
+ toadd.erase( e );
+ }
}
}
10 dbtests/jsobjtests.cpp
View
@@ -1576,6 +1576,16 @@ namespace JsobjTests {
ASSERT( s.count( a ) );
ASSERT( s.count( b ) );
ASSERT( s.count( c ) );
+
+ {
+ BSONElementSet x;
+ BSONObj o = fromjson( "{ 'a' : [ 1 , 2 , 1 ] }" );
+ BSONObjIterator i( o["a"].embeddedObjectUserCheck() );
+ while ( i.more() ){
+ x.insert( i.next() );
+ }
+ ASSERT_EQUALS( 2U , x.size() );
+ }
}
};
3  jstests/update_addToSet3.js
View
@@ -13,3 +13,6 @@ 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" )
+t.update( { _id : 1 } , { $addToSet : { a : { $each : [ 12 , 13 , 12 ] } } } )
+assert.eq( t.findOne() , { _id : 1 , a : [ 6 , 5 , 4 , 3 , 2 , 1 , 7 , 9 , 12 , 13 ] } , "A4" )
+
Please sign in to comment.
Something went wrong with that request. Please try again.