Merge pull request #31 from utopia-php/exclude-read-concern-commands

Exclude read concern commands
This commit is contained in:
Jake Barnby authored and GitHub committed 2025-10-20 11:11:23 +00:00
commit 34bc0cda8e
2 files changed
+18 -6

No files matched your search

+18 -2
View File
@@ -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 do not support readConcern options
*/
private array $readConcernNotSupportedCommands = [
self::COMMAND_GET_MORE,
self::COMMAND_KILL_CURSORS
];
/**
* Authentication for connection
@@ -320,7 +328,15 @@ 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 readConcernNotSupportedCommands array
if (
(
isset($command['txnNumber'])
&& !isset($command['startTransaction'])
&& isset($command['readConcern'])
)
|| \in_array(array_key_first($command) ?? '', $this->readConcernNotSupportedCommands)
) {
unset($command['readConcern']);
}
-4
View File
@@ -162,7 +162,6 @@ class TransactionTest extends TestCase
// Verify final state
$finalState = $client->getSessionState($session);
$this->assertEquals('committed', $finalState['state']);
} finally {
$client->endSessions([$session]);
}
@@ -202,7 +201,6 @@ class TransactionTest extends TestCase
// Verify document was not inserted (transaction rolled back)
$found = $client->find('test_collection', ['name' => 'abort_test']);
$this->assertEmpty($found->cursor->firstBatch);
} finally {
$client->endSessions([$session]);
}
@@ -251,7 +249,6 @@ class TransactionTest extends TestCase
$this->assertNotEmpty($found1->cursor->firstBatch);
$this->assertNotEmpty($found2->cursor->firstBatch);
} finally {
$client->endSessions([$session]);
}
@@ -343,7 +340,6 @@ class TransactionTest extends TestCase
$this->assertEquals(1, $count);
$client->commitTransaction($session);
} finally {
$client->endSessions([$session]);
}