Skip to content

Commit 3f6d432

Browse files
alcaeusjmikola
authored andcommitted
Remove obsolete wire version checks for MongoDB 4.2
1 parent 75fa63e commit 3f6d432

File tree

5 files changed

+6
-42
lines changed

5 files changed

+6
-42
lines changed

psalm-baseline.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -813,9 +813,6 @@
813813
</PossiblyInvalidArgument>
814814
</file>
815815
<file src="src/Operation/Update.php">
816-
<MixedArgument>
817-
<code><![CDATA[$this->options['writeConcern']]]></code>
818-
</MixedArgument>
819816
<MixedAssignment>
820817
<code><![CDATA[$cmd['bypassDocumentValidation']]]></code>
821818
<code><![CDATA[$options[$option]]]></code>

src/Collection.php

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,6 @@ class Collection implements Stringable
8787
'root' => BSONDocument::class,
8888
];
8989

90-
private const WIRE_VERSION_FOR_READ_CONCERN_WITH_WRITE_STAGE = 8;
91-
9290
/** @psalm-var Encoder<array|stdClass|Document|PackedArray, mixed> */
9391
private readonly Encoder $builderEncoder;
9492

@@ -236,24 +234,17 @@ public function aggregate(array|Pipeline $pipeline, array $options = []): Cursor
236234
$hasWriteStage = is_last_pipeline_operator_write($pipeline);
237235

238236
$options = $this->inheritReadPreference($options);
239-
240-
$server = $hasWriteStage
241-
? select_server_for_aggregate_write_stage($this->manager, $options)
242-
: select_server($this->manager, $options);
243-
244-
/* MongoDB 4.2 and later supports a read concern when an $out stage is
245-
* being used, but earlier versions do not.
246-
*/
247-
if (! $hasWriteStage || server_supports_feature($server, self::WIRE_VERSION_FOR_READ_CONCERN_WITH_WRITE_STAGE)) {
248-
$options = $this->inheritReadConcern($options);
249-
}
250-
237+
$options = $this->inheritReadConcern($options);
251238
$options = $this->inheritCodecOrTypeMap($options);
252239

253240
if ($hasWriteStage) {
254241
$options = $this->inheritWriteOptions($options);
255242
}
256243

244+
$server = $hasWriteStage
245+
? select_server_for_aggregate_write_stage($this->manager, $options)
246+
: select_server($this->manager, $options);
247+
257248
$operation = new Aggregate($this->databaseName, $this->collectionName, $pipeline, $options);
258249

259250
return $operation->execute($server);

src/Database.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,6 @@ class Database implements Stringable
6666
'root' => BSONDocument::class,
6767
];
6868

69-
private const WIRE_VERSION_FOR_READ_CONCERN_WITH_WRITE_STAGE = 8;
70-
7169
/** @psalm-var Encoder<array|stdClass|Document|PackedArray, mixed> */
7270
private readonly Encoder $builderEncoder;
7371

@@ -229,8 +227,7 @@ public function aggregate(array|Pipeline $pipeline, array $options = []): Cursor
229227
*/
230228
if (
231229
! isset($options['readConcern']) &&
232-
! is_in_transaction($options) &&
233-
( ! $hasWriteStage || server_supports_feature($server, self::WIRE_VERSION_FOR_READ_CONCERN_WITH_WRITE_STAGE))
230+
! is_in_transaction($options)
234231
) {
235232
$options['readConcern'] = $this->readConcern;
236233
}

src/Operation/FindAndModify.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ final class FindAndModify implements Explainable
5555
{
5656
private const WIRE_VERSION_FOR_HINT = 9;
5757

58-
private const WIRE_VERSION_FOR_UNSUPPORTED_OPTION_SERVER_SIDE_ERROR = 8;
59-
6058
private array $options;
6159

6260
/**
@@ -227,12 +225,6 @@ public function __construct(private string $databaseName, private string $collec
227225
*/
228226
public function execute(Server $server): array|object|null
229227
{
230-
/* Server versions >= 4.2.0 raise errors for unsupported update options.
231-
* For previous versions, the CRUD spec requires a client-side error. */
232-
if (isset($this->options['hint']) && ! server_supports_feature($server, self::WIRE_VERSION_FOR_UNSUPPORTED_OPTION_SERVER_SIDE_ERROR)) {
233-
throw UnsupportedException::hintNotSupported();
234-
}
235-
236228
/* CRUD spec requires a client-side error when using "hint" with an
237229
* unacknowledged write concern on an unsupported server. */
238230
if (

src/Operation/Update.php

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@
3232
use function MongoDB\is_document;
3333
use function MongoDB\is_first_key_operator;
3434
use function MongoDB\is_pipeline;
35-
use function MongoDB\is_write_concern_acknowledged;
36-
use function MongoDB\server_supports_feature;
3735

3836
/**
3937
* Operation for the update command.
@@ -46,8 +44,6 @@
4644
*/
4745
final class Update implements Explainable
4846
{
49-
private const WIRE_VERSION_FOR_HINT = 8;
50-
5147
private array $options;
5248

5349
/**
@@ -176,15 +172,6 @@ public function __construct(private string $databaseName, private string $collec
176172
*/
177173
public function execute(Server $server): UpdateResult
178174
{
179-
/* CRUD spec requires a client-side error when using "hint" with an
180-
* unacknowledged write concern on an unsupported server. */
181-
if (
182-
isset($this->options['writeConcern']) && ! is_write_concern_acknowledged($this->options['writeConcern']) &&
183-
isset($this->options['hint']) && ! server_supports_feature($server, self::WIRE_VERSION_FOR_HINT)
184-
) {
185-
throw UnsupportedException::hintNotSupported();
186-
}
187-
188175
$inTransaction = isset($this->options['session']) && $this->options['session']->isInTransaction();
189176
if ($inTransaction && isset($this->options['writeConcern'])) {
190177
throw UnsupportedException::writeConcernNotSupportedInTransaction();

0 commit comments

Comments
 (0)