From 74e8fad18208adf9eb61a747c03fe3b721955a33 Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Mon, 3 Nov 2025 13:28:20 +0100 Subject: [PATCH] PHPLIB-1699: Support builder pipelines in findOneAndUpdate --- src/Collection.php | 1 + .../Collection/BuilderCollectionFunctionalTest.php | 14 ++++++++++++++ 2 files changed, 15 insertions(+) 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]);