diff --git a/src/Collection.php b/src/Collection.php index d45411900..8cc513e9a 100644 --- a/src/Collection.php +++ b/src/Collection.php @@ -754,6 +754,7 @@ public function findOneAndReplace(array|object $filter, array|object $replacemen public function findOneAndUpdate(array|object $filter, array|object $update, array $options = []): array|object|null { $filter = $this->builderEncoder->encodeIfSupported($filter); + $update = $this->builderEncoder->encodeIfSupported($update); $options = $this->inheritWriteOptions($options); $options = $this->inheritCodecOrTypeMap($options); diff --git a/tests/Collection/BuilderCollectionFunctionalTest.php b/tests/Collection/BuilderCollectionFunctionalTest.php index 1075c7aa8..484ad972d 100644 --- a/tests/Collection/BuilderCollectionFunctionalTest.php +++ b/tests/Collection/BuilderCollectionFunctionalTest.php @@ -186,6 +186,20 @@ public function testFindOneAndUpdate(): void $this->assertEquals(3, $result->x); } + public function testFindOneAndUpdateWithPipelineUpdate(): void + { + $result = $this->collection->findOneAndUpdate( + Query::query(x: Query::lt(2)), + new Pipeline( + Stage::set(x: 3), + ), + ); + $this->assertEquals(1, $result->x); + + $result = $this->collection->findOne(Query::query(x: Query::eq(3))); + $this->assertEquals(3, $result->x); + } + public function testReplaceOne(): void { $this->collection->insertOne(['x' => 1]);