summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlberto Lerner <alerner@10gen.com>2012-10-17 11:22:08 -0400
committerAlberto Lerner <alerner@10gen.com>2012-10-17 15:46:11 -0400
commit54217e5e20eb5d1604dba4bf8f3368903f23686b (patch)
tree4976544c3b55aa00f20ef7269b3b009b3c396705
parentb73c4888f7cedb7b22eb211a08685576c3691eb6 (diff)
downloadmongo-54217e5e20eb5d1604dba4bf8f3368903f23686b.tar.gz
SERVER-7186 Fixed addToSet logging for an element that exists and is not at the end of the array.
-rw-r--r--src/mongo/db/ops/update_internal.cpp10
-rw-r--r--src/mongo/dbtests/updatetests.cpp6
2 files changed, 10 insertions, 6 deletions
diff --git a/src/mongo/db/ops/update_internal.cpp b/src/mongo/db/ops/update_internal.cpp
index c7448a04525..5569c6f10c3 100644
--- a/src/mongo/db/ops/update_internal.cpp
+++ b/src/mongo/db/ops/update_internal.cpp
@@ -178,12 +178,16 @@ namespace mongo {
else {
bool found = false;
-
+ int pos = 0;
+ int count = 0;
while ( i.more() ) {
BSONElement cur = i.next();
bb.append( cur );
- if ( elt.woCompare( cur , false ) == 0 )
+ if ( elt.woCompare( cur , false ) == 0 ) {
found = true;
+ pos = count;
+ }
+ count++;
}
if ( !found ) {
@@ -196,7 +200,7 @@ namespace mongo {
(elt.type() != Object) ) {
ms.fixedOpName = "$set";
ms.forcePositional = true;
- ms.position = bb.arrSize() - 1;
+ ms.position = found ? pos : bb.arrSize() - 1;
bb.done();
}
else {
diff --git a/src/mongo/dbtests/updatetests.cpp b/src/mongo/dbtests/updatetests.cpp
index 78f2dba22c0..89fe9a57f0a 100644
--- a/src/mongo/dbtests/updatetests.cpp
+++ b/src/mongo/dbtests/updatetests.cpp
@@ -929,13 +929,13 @@ namespace UpdateTests {
class AddToSetRewriteInPlace {
public:
void run() {
- BSONObj obj = BSON( "a" << BSON_ARRAY( 1 ) );
+ BSONObj obj = BSON( "a" << BSON_ARRAY( 1 << 2 ) );
BSONObj mod = BSON( "$addToSet" << BSON( "a" << 1 ) );
ModSet modSet( mod );
auto_ptr<ModSetState> modSetState = modSet.prepare( obj );
ASSERT_TRUE( modSetState->canApplyInPlace() );
modSetState->applyModsInPlace(false);
- ASSERT_EQUALS( BSON( "$set" << BSON( "a" << BSON_ARRAY( 1 ) ) ),
+ ASSERT_EQUALS( BSON( "$set" << BSON( "a" << BSON_ARRAY( 1 << 2 ) ) ),
modSetState->getOpLogRewrite() );
}
};
@@ -943,7 +943,7 @@ namespace UpdateTests {
class AddToSetRewriteForceNotInPlace {
public:
void run() {
- BSONObj obj = BSON( "a" << BSON_ARRAY( 1 ) );
+ BSONObj obj = BSON( "a" << BSON_ARRAY( 1 << 2 ) );
BSONObj mod = BSON( "$addToSet" << BSON( "a" << 1 ) );
ModSet modSet( mod );
auto_ptr<ModSetState> modSetState = modSet.prepare( obj );