diff --git a/lib/Mongo/MongoCollection.php b/lib/Mongo/MongoCollection.php index d9ea40f1..c18ffb5b 100644 --- a/lib/Mongo/MongoCollection.php +++ b/lib/Mongo/MongoCollection.php @@ -503,7 +503,7 @@ public function findAndModify(array $query, array $update = null, array $fields } else { $update = is_array($update) ? $update : []; if (isset($options['update']) && is_array($options['update'])) { - $update = array_merge($update, $options['update']); + $update = $options['update']; unset($options['update']); } diff --git a/tests/Alcaeus/MongoDbAdapter/Mongo/MongoCollectionTest.php b/tests/Alcaeus/MongoDbAdapter/Mongo/MongoCollectionTest.php index 450118af..e0a0e990 100644 --- a/tests/Alcaeus/MongoDbAdapter/Mongo/MongoCollectionTest.php +++ b/tests/Alcaeus/MongoDbAdapter/Mongo/MongoCollectionTest.php @@ -1254,6 +1254,35 @@ public function testFindAndModifyUpdateWithUpdateOptions() $this->assertObjectNotHasAttribute('foo', $object); } + public function testFindAndModifyWithUpdateParamAndOption() + { + $id = '54203e08d51d4a1f868b456e'; + $collection = $this->getCollection(); + + $document = ['_id' => new \MongoId($id), 'foo' => 'bar']; + $collection->insert($document); + + $data = ['foo' => 'foo', 'bar' => 'bar']; + + $this->getCollection()->findAndModify( + ['_id' => new \MongoId($id)], + [$data], + [], + [ + 'update' => ['$set' => ['foo' => 'foobar']], + 'upsert' => true, + ] + ); + + $newCollection = $this->getCheckDatabase()->selectCollection('test'); + $this->assertSame(1, $newCollection->count()); + $object = $newCollection->findOne(); + + $this->assertNotNull($object); + $this->assertAttributeSame('foobar', 'foo', $object); + $this->assertObjectNotHasAttribute('bar', $object); + } + public function testFindAndModifyUpdateReplace() { $id = '54203e08d51d4a1f868b456e';