Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
14 changes: 14 additions & 0 deletions tests/Collection/BuilderCollectionFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down