Skip to content

Commit 1ee02a2

Browse files
committed
Remove obsolete wire version checks
1 parent 726cba9 commit 1ee02a2

File tree

4 files changed

+6
-39
lines changed

4 files changed

+6
-39
lines changed

src/Collection.php

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,6 @@ class Collection
8585
'root' => BSONDocument::class,
8686
];
8787

88-
private const WIRE_VERSION_FOR_READ_CONCERN_WITH_WRITE_STAGE = 8;
89-
9088
/** @psalm-var Encoder<array|stdClass|Document|PackedArray, mixed> */
9189
private readonly Encoder $builderEncoder;
9290

@@ -227,24 +225,17 @@ public function aggregate(array|Pipeline $pipeline, array $options = []): Cursor
227225
$hasWriteStage = is_last_pipeline_operator_write($pipeline);
228226

229227
$options = $this->inheritReadPreference($options);
230-
231-
$server = $hasWriteStage
232-
? select_server_for_aggregate_write_stage($this->manager, $options)
233-
: select_server($this->manager, $options);
234-
235-
/* MongoDB 4.2 and later supports a read concern when an $out stage is
236-
* being used, but earlier versions do not.
237-
*/
238-
if (! $hasWriteStage || server_supports_feature($server, self::WIRE_VERSION_FOR_READ_CONCERN_WITH_WRITE_STAGE)) {
239-
$options = $this->inheritReadConcern($options);
240-
}
241-
228+
$options = $this->inheritReadConcern($options);
242229
$options = $this->inheritCodecOrTypeMap($options);
243230

244231
if ($hasWriteStage) {
245232
$options = $this->inheritWriteOptions($options);
246233
}
247234

235+
$server = $hasWriteStage
236+
? select_server_for_aggregate_write_stage($this->manager, $options)
237+
: select_server($this->manager, $options);
238+
248239
$operation = new Aggregate($this->databaseName, $this->collectionName, $pipeline, $options);
249240

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

src/Database.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,6 @@ class Database
6464
'root' => BSONDocument::class,
6565
];
6666

67-
private const WIRE_VERSION_FOR_READ_CONCERN_WITH_WRITE_STAGE = 8;
68-
6967
/** @psalm-var Encoder<array|stdClass|Document|PackedArray, mixed> */
7068
private readonly Encoder $builderEncoder;
7169

@@ -220,8 +218,7 @@ public function aggregate(array|Pipeline $pipeline, array $options = []): Cursor
220218
*/
221219
if (
222220
! isset($options['readConcern']) &&
223-
! is_in_transaction($options) &&
224-
( ! $hasWriteStage || server_supports_feature($server, self::WIRE_VERSION_FOR_READ_CONCERN_WITH_WRITE_STAGE))
221+
! is_in_transaction($options)
225222
) {
226223
$options['readConcern'] = $this->readConcern;
227224
}

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)