@@ -66,7 +66,7 @@ class Client
6666 public const COMMAND_END_SESSIONS = "endSessions " ;
6767 public const COMMAND_LIST_INDEXES = "listIndexes " ;
6868 public const COMMAND_COLLMOD = "collMod " ;
69-
69+ public const COMMAND_KILL_CURSORS = " killCursors " ;
7070 // Connection and performance settings
7171 private int $ defaultMaxTimeMS = 30000 ; // 30 seconds default
7272
@@ -97,6 +97,14 @@ class Client
9797 public const READ_PREFERENCE_SECONDARY_PREFERRED = 'secondaryPreferred ' ;
9898 public const READ_PREFERENCE_NEAREST = 'nearest ' ;
9999
100+ /**
101+ * Commands that do not support readConcern options
102+ */
103+ private array $ readConcernNotSupportedCommands = [
104+ self ::COMMAND_GET_MORE ,
105+ self ::COMMAND_KILL_CURSORS
106+ ];
107+
100108
101109 /**
102110 * Authentication for connection
@@ -320,7 +328,15 @@ public function query(array $command, ?string $db = null): stdClass|array|int
320328
321329 // CRITICAL: Remove readConcern from any non-first operation in a transaction
322330 // MongoDB will reject commands with readConcern that have txnNumber but not startTransaction
323- if (isset ($ command ['txnNumber ' ]) && !isset ($ command ['startTransaction ' ]) && isset ($ command ['readConcern ' ])) {
331+ // Or if the command is in the readConcernNotSupportedCommands array
332+ if (
333+ (
334+ isset ($ command ['txnNumber ' ])
335+ && !isset ($ command ['startTransaction ' ])
336+ && isset ($ command ['readConcern ' ])
337+ )
338+ || \in_array (array_key_first ($ command ) ?? '' , $ this ->readConcernNotSupportedCommands )
339+ ) {
324340 unset($ command ['readConcern ' ]);
325341 }
326342
0 commit comments