From 4d8fa414883a0775f8e57344c3d88adf97d9b2dd Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Thu, 2 Oct 2025 17:20:36 +1300 Subject: [PATCH] Fix return value for update --- src/Client.php | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/Client.php b/src/Client.php index 63007b715f..a10580a1c2 100644 --- a/src/Client.php +++ b/src/Client.php @@ -806,10 +806,10 @@ class Client * - arrayFilters: Array filters for updates * @param bool $multi Whether to update multiple documents * - * @return Client + * @return int Number of modified documents * @throws Exception */ - public function update(string $collection, array $where = [], array $updates = [], array $options = [], bool $multi = false): self + public function update(string $collection, array $where = [], array $updates = [], array $options = [], bool $multi = false): int { // Build command with session and concerns $command = [ @@ -843,9 +843,7 @@ class Client $otherOptions = array_diff_key($options, array_flip(['session', 'writeConcern', 'readConcern', 'upsert'])); $command = array_merge($command, $otherOptions); - $this->query($command); - - return $this; + return $this->query($command); } /** @@ -856,10 +854,10 @@ class Client * @param array $operations Array of operations, each with 'filter' and 'update' keys * @param array $options * - * @return self + * @return int Number of modified documents * @throws Exception */ - public function upsert(string $collection, array $operations, array $options = []): self + public function upsert(string $collection, array $operations, array $options = []): int { $updates = []; @@ -874,7 +872,7 @@ class Client $updates[] = $updateOperation; } - $this->query( + return $this->query( array_merge( [ self::COMMAND_UPDATE => $collection, @@ -883,7 +881,6 @@ class Client $options ) ); - return $this; }