diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 4d99d5c0c..69470d320 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -813,9 +813,6 @@ - - options['writeConcern']]]> - diff --git a/src/Collection.php b/src/Collection.php index 8cc513e9a..290bb8d4b 100644 --- a/src/Collection.php +++ b/src/Collection.php @@ -87,8 +87,6 @@ class Collection implements Stringable 'root' => BSONDocument::class, ]; - private const WIRE_VERSION_FOR_READ_CONCERN_WITH_WRITE_STAGE = 8; - /** @psalm-var Encoder */ private readonly Encoder $builderEncoder; @@ -236,24 +234,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 be5803e34..f0b781397 100644 --- a/src/Database.php +++ b/src/Database.php @@ -66,8 +66,6 @@ class Database implements Stringable 'root' => BSONDocument::class, ]; - private const WIRE_VERSION_FOR_READ_CONCERN_WITH_WRITE_STAGE = 8; - /** @psalm-var Encoder */ private readonly Encoder $builderEncoder; @@ -229,8 +227,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(); diff --git a/tests/Collection/BuilderCollectionFunctionalTest.php b/tests/Collection/BuilderCollectionFunctionalTest.php index 484ad972d..47a3a728c 100644 --- a/tests/Collection/BuilderCollectionFunctionalTest.php +++ b/tests/Collection/BuilderCollectionFunctionalTest.php @@ -231,8 +231,6 @@ public function testUpdateOne(): void public function testUpdateWithPipeline(): void { - $this->skipIfServerVersion('<', '4.2.0', 'Pipeline-style updates are not supported'); - $result = $this->collection->updateOne( Query::query(x: Query::lt(2)), new Pipeline( @@ -259,8 +257,6 @@ public function testUpdateMany(): void public function testUpdateManyWithPipeline(): void { - $this->skipIfServerVersion('<', '4.2.0', 'Pipeline-style updates are not supported'); - $result = $this->collection->updateMany( Query::query(x: Query::gt(1)), new Pipeline( diff --git a/tests/FunctionalTestCase.php b/tests/FunctionalTestCase.php index 156d80149..8a55fcfa0 100644 --- a/tests/FunctionalTestCase.php +++ b/tests/FunctionalTestCase.php @@ -469,10 +469,6 @@ protected function skipIfCausalConsistencyIsNotSupported(): void protected function skipIfClientSideEncryptionIsNotSupported(): void { - if (version_compare($this->getFeatureCompatibilityVersion(), '4.2', '<')) { - $this->markTestSkipped('Client Side Encryption only supported on FCV 4.2 or higher'); - } - if (static::getModuleInfo('libmongocrypt') === 'disabled') { $this->markTestSkipped('Client Side Encryption is not enabled in the MongoDB extension'); } @@ -495,10 +491,6 @@ protected function skipIfTransactionsAreNotSupported(): void $this->markTestSkipped('Transactions are not supported on standalone servers'); } - if ($this->isShardedCluster()) { - $this->markTestSkipped('Transactions are only supported on FCV 4.2 or higher'); - } - if ($this->getServerStorageEngine() !== 'wiredTiger') { $this->markTestSkipped('Transactions require WiredTiger storage engine'); } diff --git a/tests/Operation/BulkWriteFunctionalTest.php b/tests/Operation/BulkWriteFunctionalTest.php index 9fce1c8ac..08380dfad 100644 --- a/tests/Operation/BulkWriteFunctionalTest.php +++ b/tests/Operation/BulkWriteFunctionalTest.php @@ -198,10 +198,6 @@ function (array $event) use ($expectedReplacement): void { #[DataProvider('provideUpdatePipelines')] public function testUpdateDocuments($update, $expectedUpdate): void { - if (is_array($expectedUpdate)) { - $this->skipIfServerVersion('<', '4.2.0', 'Pipeline-style updates are not supported'); - } - (new CommandObserver())->observe( function () use ($update): void { $operation = new BulkWrite( @@ -423,8 +419,6 @@ function (array $event): void { public function testBulkWriteWithPipelineUpdates(): void { - $this->skipIfServerVersion('<', '4.2.0', 'Pipeline-style updates are not supported'); - $this->createFixtures(4); $ops = [ diff --git a/tests/Operation/ExplainFunctionalTest.php b/tests/Operation/ExplainFunctionalTest.php index 772479deb..4facde707 100644 --- a/tests/Operation/ExplainFunctionalTest.php +++ b/tests/Operation/ExplainFunctionalTest.php @@ -322,8 +322,6 @@ public function testAggregate(): void #[DataProvider('provideVerbosityInformation')] public function testAggregateOptimizedToQuery($verbosity, $executionStatsExpected, $allPlansExecutionExpected): void { - $this->skipIfServerVersion('<', '4.2.0', 'MongoDB < 4.2 does not optimize simple aggregation pipelines'); - $this->createFixtures(3); $pipeline = [['$match' => ['_id' => ['$ne' => 2]]]]; diff --git a/tests/Operation/FindAndModifyFunctionalTest.php b/tests/Operation/FindAndModifyFunctionalTest.php index 576b0474c..086575caa 100644 --- a/tests/Operation/FindAndModifyFunctionalTest.php +++ b/tests/Operation/FindAndModifyFunctionalTest.php @@ -126,22 +126,6 @@ function (array $event): void { ); } - public function testHintOptionUnsupportedClientSideError(): void - { - $this->skipIfServerVersion('>=', '4.2.0', 'server reports error for unsupported findAndModify options'); - - $operation = new FindAndModify( - $this->getDatabaseName(), - $this->getCollectionName(), - ['remove' => true, 'hint' => '_id_'], - ); - - $this->expectException(UnsupportedException::class); - $this->expectExceptionMessage('Hint is not supported by the server executing this operation'); - - $operation->execute($this->getPrimaryServer()); - } - public function testHintOptionAndUnacknowledgedWriteConcernUnsupportedClientSideError(): void { $this->skipIfServerVersion('>=', '4.4.0', 'hint is supported'); diff --git a/tests/Operation/UpdateFunctionalTest.php b/tests/Operation/UpdateFunctionalTest.php index b9424975b..568e758fa 100644 --- a/tests/Operation/UpdateFunctionalTest.php +++ b/tests/Operation/UpdateFunctionalTest.php @@ -54,10 +54,6 @@ function (array $event) use ($expectedFilter): void { #[DataProvider('provideReplacementDocumentLikePipeline')] public function testUpdateDocuments($update, $expectedUpdate): void { - if (is_array($expectedUpdate)) { - $this->skipIfServerVersion('<', '4.2.0', 'Pipeline-style updates are not supported'); - } - (new CommandObserver())->observe( function () use ($update): void { $operation = new Update( @@ -148,24 +144,6 @@ function (array $event): void { ); } - public function testHintOptionAndUnacknowledgedWriteConcernUnsupportedClientSideError(): void - { - $this->skipIfServerVersion('>=', '4.2.0', 'hint is supported'); - - $operation = new Update( - $this->getDatabaseName(), - $this->getCollectionName(), - ['_id' => 1], - ['$inc' => ['x' => 1]], - ['hint' => '_id_', 'writeConcern' => new WriteConcern(0)], - ); - - $this->expectException(UnsupportedException::class); - $this->expectExceptionMessage('Hint is not supported by the server executing this operation'); - - $operation->execute($this->getPrimaryServer()); - } - public function testUpdateOne(): void { $this->createFixtures(3); diff --git a/tests/SpecTests/PrimaryStepDownSpecTest.php b/tests/SpecTests/PrimaryStepDownSpecTest.php index bc060c061..0db02f279 100644 --- a/tests/SpecTests/PrimaryStepDownSpecTest.php +++ b/tests/SpecTests/PrimaryStepDownSpecTest.php @@ -72,43 +72,6 @@ public function testNotPrimaryKeepsConnectionPool(): void $this->assertSame($totalConnectionsCreated, $this->getTotalConnectionsCreated()); } - /** @see https://github.com/mongodb/specifications/tree/master/source/connections-survive-step-down/tests#not-primary-reset-connection-pool */ - public function testNotPrimaryResetConnectionPool(): void - { - $runOn = [(object) ['minServerVersion' => '4.0.0', 'maxServerVersion' => '4.0.999', 'topology' => [self::TOPOLOGY_REPLICASET]]]; - $this->checkServerRequirements($runOn); - - // Set a fail point - $this->configureFailPoint([ - 'configureFailPoint' => 'failCommand', - 'mode' => ['times' => 1], - 'data' => [ - 'failCommands' => ['insert'], - 'errorCode' => self::NOT_PRIMARY, - ], - ]); - - $totalConnectionsCreated = $this->getTotalConnectionsCreated(); - - // Execute an insert into the test collection of a {test: 1} document. - try { - $this->insertDocuments(1); - } catch (BulkWriteException $e) { - // Verify that the insert failed with an operation failure with 10107 code. - $this->assertSame(self::NOT_PRIMARY, $e->getCode()); - } - - /* Verify that the connection pool has been cleared and that a new - * connection has been created. Use ">=" to allow for the possibility - * that the server created additional connections unrelated to this - * test. */ - $this->assertGreaterThanOrEqual($totalConnectionsCreated + 1, $this->getTotalConnectionsCreated()); - - // Execute an insert into the test collection of a {test: 1} document and verify that it succeeds. - $result = $this->insertDocuments(1); - $this->assertSame(1, $result->getInsertedCount()); - } - /** @see https://github.com/mongodb/specifications/tree/master/source/connections-survive-step-down/tests#shutdown-in-progress-reset-connection-pool */ public function testShutdownResetConnectionPool(): void { diff --git a/tests/UnifiedSpecTests/UnifiedTestRunner.php b/tests/UnifiedSpecTests/UnifiedTestRunner.php index 3069636b7..770f44a1a 100644 --- a/tests/UnifiedSpecTests/UnifiedTestRunner.php +++ b/tests/UnifiedSpecTests/UnifiedTestRunner.php @@ -337,12 +337,6 @@ private function isAuthenticated(): bool */ private function isClientSideEncryptionSupported(): bool { - /* CSFLE technically requires FCV 4.2+ but this is sufficient since we - * do not test on mixed-version clusters. */ - if (version_compare($this->getServerVersion(), '4.2', '<')) { - return false; - } - if (FunctionalTestCase::getModuleInfo('libmongocrypt') === 'disabled') { return false; }