From 622cd6b86e07eb00092a0d92ea84e630b7058c31 Mon Sep 17 00:00:00 2001 From: shimon Date: Mon, 20 Oct 2025 13:39:42 +0300 Subject: [PATCH] Update readConcern handling for unsupported commands --- src/Client.php | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/Client.php b/src/Client.php index c6d2c91ac7..72df20acb8 100644 --- a/src/Client.php +++ b/src/Client.php @@ -66,7 +66,7 @@ class Client public const COMMAND_END_SESSIONS = "endSessions"; public const COMMAND_LIST_INDEXES = "listIndexes"; public const COMMAND_COLLMOD = "collMod"; - + public const COMMAND_KILL_CURSORS = "killCursors"; // Connection and performance settings private int $defaultMaxTimeMS = 30000; // 30 seconds default @@ -97,6 +97,14 @@ class Client public const READ_PREFERENCE_SECONDARY_PREFERRED = 'secondaryPreferred'; public const READ_PREFERENCE_NEAREST = 'nearest'; + /** + * Commands that don't support readConcern + */ + private array $readConcernNotSupporteedCommands = [ + self::COMMAND_GET_MORE, + self::COMMAND_KILL_CURSORS + ]; + /** * Authentication for connection @@ -320,7 +328,10 @@ class Client // CRITICAL: Remove readConcern from any non-first operation in a transaction // MongoDB will reject commands with readConcern that have txnNumber but not startTransaction - if (isset($command['txnNumber']) && !isset($command['startTransaction']) && isset($command['readConcern'])) { + // Or if the command is in the readConcernNotSupporteedCommands array + if (((isset($command['txnNumber']) && !isset($command['startTransaction']) && isset($command['readConcern'])) + || + in_array(array_keys($command)[0] ?? '', $this->readConcernNotSupporteedCommands))) { unset($command['readConcern']); } @@ -2051,4 +2062,4 @@ class Client { $this->close(); } -} +} \ No newline at end of file