Skip to content

Commit 75fa63e

Browse files
authored
PHPLIB-1699: Support builder pipelines in findOneAndUpdate (#1793)
1 parent 89481cc commit 75fa63e

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/Collection.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,7 @@ public function findOneAndReplace(array|object $filter, array|object $replacemen
754754
public function findOneAndUpdate(array|object $filter, array|object $update, array $options = []): array|object|null
755755
{
756756
$filter = $this->builderEncoder->encodeIfSupported($filter);
757+
$update = $this->builderEncoder->encodeIfSupported($update);
757758
$options = $this->inheritWriteOptions($options);
758759
$options = $this->inheritCodecOrTypeMap($options);
759760

tests/Collection/BuilderCollectionFunctionalTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,20 @@ public function testFindOneAndUpdate(): void
186186
$this->assertEquals(3, $result->x);
187187
}
188188

189+
public function testFindOneAndUpdateWithPipelineUpdate(): void
190+
{
191+
$result = $this->collection->findOneAndUpdate(
192+
Query::query(x: Query::lt(2)),
193+
new Pipeline(
194+
Stage::set(x: 3),
195+
),
196+
);
197+
$this->assertEquals(1, $result->x);
198+
199+
$result = $this->collection->findOne(Query::query(x: Query::eq(3)));
200+
$this->assertEquals(3, $result->x);
201+
}
202+
189203
public function testReplaceOne(): void
190204
{
191205
$this->collection->insertOne(['x' => 1]);

0 commit comments

Comments
 (0)