diff --git a/psalm-baseline.xml b/psalm-baseline.xml index a6dd2d5bf..49eed77df 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -809,9 +809,6 @@ - - options['writeConcern']]]> - diff --git a/src/Collection.php b/src/Collection.php index 04a61981c..b22e6e11b 100644 --- a/src/Collection.php +++ b/src/Collection.php @@ -85,8 +85,6 @@ class Collection 'root' => BSONDocument::class, ]; - private const WIRE_VERSION_FOR_READ_CONCERN_WITH_WRITE_STAGE = 8; - /** @psalm-var Encoder */ private readonly Encoder $builderEncoder; @@ -227,24 +225,17 @@ public function aggregate(array|Pipeline $pipeline, array $options = []): Cursor $hasWriteStage = is_last_pipeline_operator_write($pipeline); $options = $this->inheritReadPreference($options); - - $server = $hasWriteStage - ? select_server_for_aggregate_write_stage($this->manager, $options) - : select_server($this->manager, $options); - - /* MongoDB 4.2 and later supports a read concern when an $out stage is - * being used, but earlier versions do not. - */ - if (! $hasWriteStage || server_supports_feature($server, self::WIRE_VERSION_FOR_READ_CONCERN_WITH_WRITE_STAGE)) { - $options = $this->inheritReadConcern($options); - } - + $options = $this->inheritReadConcern($options); $options = $this->inheritCodecOrTypeMap($options); if ($hasWriteStage) { $options = $this->inheritWriteOptions($options); } + $server = $hasWriteStage + ? select_server_for_aggregate_write_stage($this->manager, $options) + : select_server($this->manager, $options); + $operation = new Aggregate($this->databaseName, $this->collectionName, $pipeline, $options); return $operation->execute($server); diff --git a/src/Database.php b/src/Database.php index 265772b53..aff53460e 100644 --- a/src/Database.php +++ b/src/Database.php @@ -64,8 +64,6 @@ class Database 'root' => BSONDocument::class, ]; - private const WIRE_VERSION_FOR_READ_CONCERN_WITH_WRITE_STAGE = 8; - /** @psalm-var Encoder */ private readonly Encoder $builderEncoder; @@ -220,8 +218,7 @@ public function aggregate(array|Pipeline $pipeline, array $options = []): Cursor */ if ( ! isset($options['readConcern']) && - ! is_in_transaction($options) && - ( ! $hasWriteStage || server_supports_feature($server, self::WIRE_VERSION_FOR_READ_CONCERN_WITH_WRITE_STAGE)) + ! is_in_transaction($options) ) { $options['readConcern'] = $this->readConcern; } diff --git a/src/Operation/FindAndModify.php b/src/Operation/FindAndModify.php index 3d77dd643..798d353c2 100644 --- a/src/Operation/FindAndModify.php +++ b/src/Operation/FindAndModify.php @@ -55,8 +55,6 @@ final class FindAndModify implements Explainable { private const WIRE_VERSION_FOR_HINT = 9; - private const WIRE_VERSION_FOR_UNSUPPORTED_OPTION_SERVER_SIDE_ERROR = 8; - private array $options; /** @@ -227,12 +225,6 @@ public function __construct(private string $databaseName, private string $collec */ public function execute(Server $server): array|object|null { - /* Server versions >= 4.2.0 raise errors for unsupported update options. - * For previous versions, the CRUD spec requires a client-side error. */ - if (isset($this->options['hint']) && ! server_supports_feature($server, self::WIRE_VERSION_FOR_UNSUPPORTED_OPTION_SERVER_SIDE_ERROR)) { - throw UnsupportedException::hintNotSupported(); - } - /* CRUD spec requires a client-side error when using "hint" with an * unacknowledged write concern on an unsupported server. */ if ( diff --git a/src/Operation/Update.php b/src/Operation/Update.php index 3c8118b81..4f785e7a1 100644 --- a/src/Operation/Update.php +++ b/src/Operation/Update.php @@ -32,8 +32,6 @@ use function MongoDB\is_document; use function MongoDB\is_first_key_operator; use function MongoDB\is_pipeline; -use function MongoDB\is_write_concern_acknowledged; -use function MongoDB\server_supports_feature; /** * Operation for the update command. @@ -46,8 +44,6 @@ */ final class Update implements Explainable { - private const WIRE_VERSION_FOR_HINT = 8; - private array $options; /** @@ -176,15 +172,6 @@ public function __construct(private string $databaseName, private string $collec */ public function execute(Server $server): UpdateResult { - /* CRUD spec requires a client-side error when using "hint" with an - * unacknowledged write concern on an unsupported server. */ - if ( - isset($this->options['writeConcern']) && ! is_write_concern_acknowledged($this->options['writeConcern']) && - isset($this->options['hint']) && ! server_supports_feature($server, self::WIRE_VERSION_FOR_HINT) - ) { - throw UnsupportedException::hintNotSupported(); - } - $inTransaction = isset($this->options['session']) && $this->options['session']->isInTransaction(); if ($inTransaction && isset($this->options['writeConcern'])) { throw UnsupportedException::writeConcernNotSupportedInTransaction();