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
20 changes: 18 additions & 2 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -320,7 +328,15 @@ public function query(array $command, ?string $db = null): stdClass|array|int

// 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']);
}

Expand Down
4 changes: 0 additions & 4 deletions tests/TransactionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ public function testTransactionStateManagement()
// Verify final state
$finalState = $client->getSessionState($session);
$this->assertEquals('committed', $finalState['state']);

} finally {
$client->endSessions([$session]);
}
Expand Down Expand Up @@ -202,7 +201,6 @@ public function testTransactionAbort()
// 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]);
}
Expand Down Expand Up @@ -251,7 +249,6 @@ public function testWithTransactionHelper()

$this->assertNotEmpty($found1->cursor->firstBatch);
$this->assertNotEmpty($found2->cursor->firstBatch);

} finally {
$client->endSessions([$session]);
}
Expand Down Expand Up @@ -343,7 +340,6 @@ public function testCRUDWithSessionAndConcerns()
$this->assertEquals(1, $count);

$client->commitTransaction($session);

} finally {
$client->endSessions([$session]);
}
Expand Down