summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlberto Lerner <alerner@10gen.com>2013-01-29 12:55:04 -0500
committerAlberto Lerner <alerner@10gen.com>2013-01-29 12:55:04 -0500
commit2b94e0e553d7b76b2c1a50c6e9bd6d0b4764e78c (patch)
treec9f128bbb611c0b07f505af0dbe0c30a0be0fac7
parent3ff1634cf2c24c996f426872c5fafd83dc399e51 (diff)
downloadmongo-2b94e0e553d7b76b2c1a50c6e9bd6d0b4764e78c.tar.gz
SERVER-8303 Fix $push with a single $each clause behavior.
-rw-r--r--src/mongo/db/ops/update_internal.cpp2
-rw-r--r--src/mongo/dbtests/updatetests.cpp26
2 files changed, 27 insertions, 1 deletions
diff --git a/src/mongo/db/ops/update_internal.cpp b/src/mongo/db/ops/update_internal.cpp
index 8197c7bd7e0..f77fe202ead 100644
--- a/src/mongo/db/ops/update_internal.cpp
+++ b/src/mongo/db/ops/update_internal.cpp
@@ -171,7 +171,7 @@ namespace mongo {
while ( i.more() ) {
bb.append( i.next() );
}
- BSONObjIterator j( elt.embeddedObject() );
+ BSONObjIterator j( getEach() );
while ( j.more() ) {
bb.append( j.next() );
}
diff --git a/src/mongo/dbtests/updatetests.cpp b/src/mongo/dbtests/updatetests.cpp
index 96b7af74cfe..90e208bb95b 100644
--- a/src/mongo/dbtests/updatetests.cpp
+++ b/src/mongo/dbtests/updatetests.cpp
@@ -461,6 +461,30 @@ namespace UpdateTests {
}
};
+ class PushEachSimple : public SetBase {
+ public:
+ void run() {
+ client().insert( ns(), fromjson( "{'_id':0,a:[1]}" ) );
+ // { $push : { a : { $each : [ 2, 3 ] } } }
+ BSONObj pushObj = BSON( "$each" << BSON_ARRAY( 2 << 3 ) );
+ client().update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) );
+ ASSERT_EQUALS( client().findOne( ns(), Query() ) , fromjson( "{'_id':0,a:[1,2,3]}" ) );
+ }
+
+ };
+
+ class PushEachFromEmpty : public SetBase {
+ public:
+ void run() {
+ client().insert( ns(), fromjson( "{'_id':0,a:[]}" ) );
+ // { $push : { a : { $each : [ 1, 2, 3 ] } } }
+ BSONObj pushObj = BSON( "$each" << BSON_ARRAY( 1 << 2 << 3 ) );
+ client().update( ns(), Query(), BSON( "$push" << BSON( "a" << pushObj ) ) );
+ ASSERT_EQUALS( client().findOne( ns(), Query() ) , fromjson( "{'_id':0,a:[1,2,3]}" ) );
+ }
+
+ };
+
class PushSliceBelowFull : public SetBase {
public:
void run() {
@@ -2631,6 +2655,8 @@ namespace UpdateTests {
add< CantPushTwice >();
add< SetEncapsulationConflictsWithExistingType >();
add< CantPushToParent >();
+ add< PushEachSimple >();
+ add< PushEachFromEmpty >();
add< PushSliceBelowFull >();
add< PushSliceReachedFullExact >();
add< PushSliceReachedFullWithEach >();