Skip to content

Commit 4233966

Browse files
committed
PHPLIB-1511: Remove deprecated query options
1 parent 985f4dc commit 4233966

File tree

8 files changed

+10
-183
lines changed

8 files changed

+10
-183
lines changed

UPGRADE-2.0.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ UPGRADE FROM 1.x to 2.0
66
* The `MongoDB\Operation\Watch::FULL_DOCUMENT_DEFAULT` constant has been
77
removed.
88
* The `MongoDB\Model\IndexInfo::isGeoHaystack` method has been removed.
9+
* The `maxScan`, `modifiers`, `oplogReplay`, and `snapshot` options for `find`
10+
and `findOne` operations have been removed.
911

1012
GridFS
1113
------

psalm-baseline.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -670,11 +670,7 @@
670670
<code><![CDATA[$this->options['codec']]]></code>
671671
<code><![CDATA[$this->options['typeMap']]]></code>
672672
</MixedArgument>
673-
<MixedArrayAccess>
674-
<code><![CDATA[$options['modifiers'][$modifier[1]]]]></code>
675-
</MixedArrayAccess>
676673
<MixedAssignment>
677-
<code><![CDATA[$options[$modifier[0]]]]></code>
678674
<code><![CDATA[$options[$option]]]></code>
679675
<code><![CDATA[$options['readPreference']]]></code>
680676
<code><![CDATA[$options['session']]]></code>

src/Operation/Find.php

Lines changed: 3 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,7 @@
3535
use function is_integer;
3636
use function is_object;
3737
use function is_string;
38-
use function MongoDB\document_to_array;
3938
use function MongoDB\is_document;
40-
use function trigger_error;
41-
42-
use const E_USER_DEPRECATED;
4339

4440
/**
4541
* Operation for the find command.
@@ -92,28 +88,15 @@ final class Find implements Executable, Explainable
9288
* * maxAwaitTimeMS (integer): The maxium amount of time for the server to wait
9389
* on new documents to satisfy a query, if cursorType is TAILABLE_AWAIT.
9490
*
95-
* * maxScan (integer): Maximum number of documents or index keys to scan
96-
* when executing the query.
97-
*
98-
* This option has been deprecated since version 1.4.
99-
*
10091
* * maxTimeMS (integer): The maximum amount of time to allow the query to
101-
* run. If "$maxTimeMS" also exists in the modifiers document, this
102-
* option will take precedence.
92+
* run.
10393
*
10494
* * min (document): The inclusive upper bound for a specific index.
10595
*
106-
* * modifiers (document): Meta operators that modify the output or
107-
* behavior of a query. Use of these operators is deprecated in favor of
108-
* named options.
109-
*
11096
* * noCursorTimeout (boolean): The server normally times out idle cursors
11197
* after an inactivity period (10 minutes) to prevent excess memory use.
11298
* Set this option to prevent that.
11399
*
114-
* * oplogReplay (boolean): Internal replication use only. The driver
115-
* should not set this. This option is deprecated as of MongoDB 4.4.
116-
*
117100
* * projection (document): Limits the fields to return for the matching
118101
* document.
119102
*
@@ -132,14 +115,7 @@ final class Find implements Executable, Explainable
132115
*
133116
* * skip (integer): The number of documents to skip before returning.
134117
*
135-
* * snapshot (boolean): Prevents the cursor from returning a document more
136-
* than once because of an intervening write operation.
137-
*
138-
* This options has been deprecated since version 1.4.
139-
*
140-
* * sort (document): The order in which to return matching documents. If
141-
* "$orderby" also exists in the modifiers document, this option will
142-
* take precedence.
118+
* * sort (document): The order in which to return matching documents.
143119
*
144120
* * let (document): Map of parameter names and values. Values must be
145121
* constant or closed expressions that do not reference document fields.
@@ -211,10 +187,6 @@ public function __construct(private string $databaseName, private string $collec
211187
throw InvalidArgumentException::invalidType('"maxAwaitTimeMS" option', $this->options['maxAwaitTimeMS'], 'integer');
212188
}
213189

214-
if (isset($this->options['maxScan']) && ! is_integer($this->options['maxScan'])) {
215-
throw InvalidArgumentException::invalidType('"maxScan" option', $this->options['maxScan'], 'integer');
216-
}
217-
218190
if (isset($this->options['maxTimeMS']) && ! is_integer($this->options['maxTimeMS'])) {
219191
throw InvalidArgumentException::invalidType('"maxTimeMS" option', $this->options['maxTimeMS'], 'integer');
220192
}
@@ -223,18 +195,10 @@ public function __construct(private string $databaseName, private string $collec
223195
throw InvalidArgumentException::expectedDocumentType('"min" option', $this->options['min']);
224196
}
225197

226-
if (isset($this->options['modifiers']) && ! is_document($this->options['modifiers'])) {
227-
throw InvalidArgumentException::expectedDocumentType('"modifiers" option', $this->options['modifiers']);
228-
}
229-
230198
if (isset($this->options['noCursorTimeout']) && ! is_bool($this->options['noCursorTimeout'])) {
231199
throw InvalidArgumentException::invalidType('"noCursorTimeout" option', $this->options['noCursorTimeout'], 'boolean');
232200
}
233201

234-
if (isset($this->options['oplogReplay']) && ! is_bool($this->options['oplogReplay'])) {
235-
throw InvalidArgumentException::invalidType('"oplogReplay" option', $this->options['oplogReplay'], 'boolean');
236-
}
237-
238202
if (isset($this->options['projection']) && ! is_document($this->options['projection'])) {
239203
throw InvalidArgumentException::expectedDocumentType('"projection" option', $this->options['projection']);
240204
}
@@ -263,10 +227,6 @@ public function __construct(private string $databaseName, private string $collec
263227
throw InvalidArgumentException::invalidType('"skip" option', $this->options['skip'], 'integer');
264228
}
265229

266-
if (isset($this->options['snapshot']) && ! is_bool($this->options['snapshot'])) {
267-
throw InvalidArgumentException::invalidType('"snapshot" option', $this->options['snapshot'], 'boolean');
268-
}
269-
270230
if (isset($this->options['sort']) && ! is_document($this->options['sort'])) {
271231
throw InvalidArgumentException::expectedDocumentType('"sort" option', $this->options['sort']);
272232
}
@@ -283,14 +243,6 @@ public function __construct(private string $databaseName, private string $collec
283243
unset($this->options['readConcern']);
284244
}
285245

286-
if (isset($this->options['snapshot'])) {
287-
trigger_error('The "snapshot" option is deprecated and will be removed in a future release', E_USER_DEPRECATED);
288-
}
289-
290-
if (isset($this->options['maxScan'])) {
291-
trigger_error('The "maxScan" option is deprecated and will be removed in a future release', E_USER_DEPRECATED);
292-
}
293-
294246
if (isset($this->options['codec']) && isset($this->options['typeMap'])) {
295247
throw InvalidArgumentException::cannotCombineCodecAndTypeMap();
296248
}
@@ -343,28 +295,6 @@ public function getCommandDocument()
343295
// maxAwaitTimeMS is a Query level option so should not be considered here
344296
unset($options['maxAwaitTimeMS']);
345297

346-
$modifierFallback = [
347-
['allowPartialResults', 'partial'],
348-
['comment', '$comment'],
349-
['hint', '$hint'],
350-
['maxScan', '$maxScan'],
351-
['max', '$max'],
352-
['maxTimeMS', '$maxTimeMS'],
353-
['min', '$min'],
354-
['returnKey', '$returnKey'],
355-
['showRecordId', '$showDiskLoc'],
356-
['sort', '$orderby'],
357-
['snapshot', '$snapshot'],
358-
];
359-
360-
foreach ($modifierFallback as $modifier) {
361-
if (! isset($options[$modifier[0]]) && isset($options['modifiers'][$modifier[1]])) {
362-
$options[$modifier[0]] = $options['modifiers'][$modifier[1]];
363-
}
364-
}
365-
366-
unset($options['modifiers']);
367-
368298
return $cmd + $options;
369299
}
370300

@@ -409,7 +339,7 @@ private function createQueryOptions(): array
409339
}
410340
}
411341

412-
foreach (['allowDiskUse', 'allowPartialResults', 'batchSize', 'comment', 'hint', 'limit', 'maxAwaitTimeMS', 'maxScan', 'maxTimeMS', 'noCursorTimeout', 'oplogReplay', 'projection', 'readConcern', 'returnKey', 'showRecordId', 'skip', 'snapshot', 'sort'] as $option) {
342+
foreach (['allowDiskUse', 'allowPartialResults', 'batchSize', 'comment', 'hint', 'limit', 'maxAwaitTimeMS', 'maxTimeMS', 'noCursorTimeout', 'projection', 'readConcern', 'returnKey', 'showRecordId', 'skip', 'sort'] as $option) {
413343
if (isset($this->options[$option])) {
414344
$options[$option] = $this->options[$option];
415345
}
@@ -421,12 +351,6 @@ private function createQueryOptions(): array
421351
}
422352
}
423353

424-
if (! empty($this->options['modifiers'])) {
425-
/** @psalm-var array|object */
426-
$modifiers = $this->options['modifiers'];
427-
$options['modifiers'] = is_object($modifiers) ? document_to_array($modifiers) : $modifiers;
428-
}
429-
430354
return $options;
431355
}
432356
}

src/Operation/FindOne.php

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,20 +55,11 @@ final class FindOne implements Executable, Explainable
5555
*
5656
* * max (document): The exclusive upper bound for a specific index.
5757
*
58-
* * maxScan (integer): Maximum number of documents or index keys to scan
59-
* when executing the query.
60-
*
61-
* This option has been deprecated since version 1.4.
62-
*
6358
* * maxTimeMS (integer): The maximum amount of time to allow the query to
64-
* run. If "$maxTimeMS" also exists in the modifiers document, this
65-
* option will take precedence.
59+
* run.
6660
*
6761
* * min (document): The inclusive upper bound for a specific index.
6862
*
69-
* * modifiers (document): Meta-operators modifying the output or behavior
70-
* of a query.
71-
*
7263
* * projection (document): Limits the fields to return for the matching
7364
* document.
7465
*
@@ -87,9 +78,7 @@ final class FindOne implements Executable, Explainable
8778
*
8879
* * skip (integer): The number of documents to skip before returning.
8980
*
90-
* * sort (document): The order in which to return matching documents. If
91-
* "$orderby" also exists in the modifiers document, this option will
92-
* take precedence.
81+
* * sort (document): The order in which to return matching documents.
9382
*
9483
* * let (document): Map of parameter names and values. Values must be
9584
* constant or closed expressions that do not reference document fields.

tests/Operation/ExplainFunctionalTest.php

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -157,30 +157,6 @@ function (array $event): void {
157157
);
158158
}
159159

160-
public function testFindModifiers(): void
161-
{
162-
$this->createFixtures(3);
163-
164-
$operation = new Find(
165-
$this->getDatabaseName(),
166-
$this->getCollectionName(),
167-
[],
168-
['modifiers' => ['$orderby' => ['_id' => 1]]],
169-
);
170-
171-
(new CommandObserver())->observe(
172-
function () use ($operation): void {
173-
$explainOperation = new Explain($this->getDatabaseName(), $operation, ['typeMap' => ['root' => 'array', 'document' => 'array']]);
174-
$explainOperation->execute($this->getPrimaryServer());
175-
},
176-
function (array $event): void {
177-
$command = $event['started']->getCommand();
178-
$this->assertObjectHasProperty('sort', $command->explain);
179-
$this->assertObjectNotHasProperty('modifiers', $command->explain);
180-
},
181-
);
182-
}
183-
184160
/** @dataProvider provideVerbosityInformation */
185161
public function testFindOne($verbosity, $executionStatsExpected, $allPlansExecutionExpected): void
186162
{

tests/Operation/FindFunctionalTest.php

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22

33
namespace MongoDB\Tests\Operation;
44

5-
use MongoDB\BSON\Document;
65
use MongoDB\Driver\BulkWrite;
76
use MongoDB\Driver\ReadPreference;
8-
use MongoDB\Model\BSONDocument;
97
use MongoDB\Operation\CreateIndexes;
108
use MongoDB\Operation\Find;
119
use MongoDB\Tests\CommandObserver;
@@ -36,38 +34,6 @@ function (array $event) use ($expectedQuery): void {
3634
);
3735
}
3836

39-
/** @dataProvider provideModifierDocuments */
40-
public function testModifierDocuments($modifiers, stdClass $expectedSort): void
41-
{
42-
(new CommandObserver())->observe(
43-
function () use ($modifiers): void {
44-
$operation = new Find(
45-
$this->getDatabaseName(),
46-
$this->getCollectionName(),
47-
[],
48-
['modifiers' => $modifiers],
49-
);
50-
51-
$operation->execute($this->getPrimaryServer());
52-
},
53-
function (array $event) use ($expectedSort): void {
54-
$this->assertEquals($expectedSort, $event['started']->getCommand()->sort ?? null);
55-
},
56-
);
57-
}
58-
59-
public static function provideModifierDocuments(): array
60-
{
61-
$expectedSort = (object) ['x' => 1];
62-
63-
return [
64-
'array' => [['$orderby' => ['x' => 1]], $expectedSort],
65-
'object' => [(object) ['$orderby' => ['x' => 1]], $expectedSort],
66-
'Serializable' => [new BSONDocument(['$orderby' => ['x' => 1]]), $expectedSort],
67-
'Document' => [Document::fromPHP(['$orderby' => ['x' => 1]]), $expectedSort],
68-
];
69-
}
70-
7137
public function testDefaultReadConcernIsOmitted(): void
7238
{
7339
(new CommandObserver())->observe(

tests/Operation/FindTest.php

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -37,42 +37,20 @@ public static function provideInvalidConstructorOptions()
3737
'limit' => self::getInvalidIntegerValues(),
3838
'max' => self::getInvalidDocumentValues(),
3939
'maxAwaitTimeMS' => self::getInvalidIntegerValues(),
40-
'maxScan' => self::getInvalidIntegerValues(),
4140
'maxTimeMS' => self::getInvalidIntegerValues(),
4241
'min' => self::getInvalidDocumentValues(),
43-
'modifiers' => self::getInvalidDocumentValues(),
44-
'oplogReplay' => self::getInvalidBooleanValues(),
4542
'projection' => self::getInvalidDocumentValues(),
4643
'readConcern' => self::getInvalidReadConcernValues(),
4744
'readPreference' => self::getInvalidReadPreferenceValues(),
4845
'returnKey' => self::getInvalidBooleanValues(),
4946
'session' => self::getInvalidSessionValues(),
5047
'showRecordId' => self::getInvalidBooleanValues(),
5148
'skip' => self::getInvalidIntegerValues(),
52-
'snapshot' => self::getInvalidBooleanValues(),
5349
'sort' => self::getInvalidDocumentValues(),
5450
'typeMap' => self::getInvalidArrayValues(),
5551
]);
5652
}
5753

58-
public function testSnapshotOptionIsDeprecated(): void
59-
{
60-
$this->assertDeprecated(function (): void {
61-
new Find($this->getDatabaseName(), $this->getCollectionName(), [], ['snapshot' => true]);
62-
});
63-
64-
$this->assertDeprecated(function (): void {
65-
new Find($this->getDatabaseName(), $this->getCollectionName(), [], ['snapshot' => false]);
66-
});
67-
}
68-
69-
public function testMaxScanOptionIsDeprecated(): void
70-
{
71-
$this->assertDeprecated(function (): void {
72-
new Find($this->getDatabaseName(), $this->getCollectionName(), [], ['maxScan' => 1]);
73-
});
74-
}
75-
7654
/** @dataProvider provideInvalidConstructorCursorTypeOptions */
7755
public function testConstructorCursorTypeOption($cursorType): void
7856
{
@@ -87,7 +65,6 @@ public static function provideInvalidConstructorCursorTypeOptions()
8765

8866
public function testExplainableCommandDocument(): void
8967
{
90-
// all options except deprecated "snapshot" and "maxScan"
9168
$options = [
9269
'allowDiskUse' => true,
9370
'allowPartialResults' => true,
@@ -100,7 +77,6 @@ public function testExplainableCommandDocument(): void
10077
'maxTimeMS' => 100,
10178
'min' => ['x' => 10],
10279
'noCursorTimeout' => true,
103-
'oplogReplay' => true,
10480
'projection' => ['_id' => 0],
10581
'readConcern' => new ReadConcern(ReadConcern::LOCAL),
10682
'returnKey' => true,
@@ -111,7 +87,6 @@ public function testExplainableCommandDocument(): void
11187
// Intentionally omitted options
11288
'cursorType' => Find::NON_TAILABLE,
11389
'maxAwaitTimeMS' => 500,
114-
'modifiers' => ['foo' => 'bar'],
11590
'readPreference' => new ReadPreference(ReadPreference::SECONDARY_PREFERRED),
11691
'typeMap' => ['root' => 'array'],
11792
];
@@ -128,7 +103,6 @@ public function testExplainableCommandDocument(): void
128103
'limit' => 15,
129104
'maxTimeMS' => 100,
130105
'noCursorTimeout' => true,
131-
'oplogReplay' => true,
132106
'projection' => ['_id' => 0],
133107
'readConcern' => new ReadConcern(ReadConcern::LOCAL),
134108
'returnKey' => true,

tests/UnifiedSpecTests/Util.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ final class Util
8787
'aggregate' => ['pipeline', 'session', 'allowDiskUse', 'batchSize', 'bypassDocumentValidation', 'collation', 'comment', 'explain', 'hint', 'let', 'maxAwaitTimeMS', 'maxTimeMS'],
8888
'bulkWrite' => ['let', 'requests', 'session', 'ordered', 'bypassDocumentValidation', 'comment'],
8989
'createChangeStream' => ['pipeline', 'session', 'fullDocument', 'fullDocumentBeforeChange', 'resumeAfter', 'startAfter', 'startAtOperationTime', 'batchSize', 'collation', 'maxAwaitTimeMS', 'comment', 'showExpandedEvents'],
90-
'createFindCursor' => ['filter', 'session', 'allowDiskUse', 'allowPartialResults', 'batchSize', 'collation', 'comment', 'cursorType', 'hint', 'limit', 'max', 'maxAwaitTimeMS', 'maxScan', 'maxTimeMS', 'min', 'modifiers', 'noCursorTimeout', 'oplogReplay', 'projection', 'returnKey', 'showRecordId', 'skip', 'snapshot', 'sort'],
90+
'createFindCursor' => ['filter', 'session', 'allowDiskUse', 'allowPartialResults', 'batchSize', 'collation', 'comment', 'cursorType', 'hint', 'limit', 'max', 'maxAwaitTimeMS', 'maxTimeMS', 'min', 'noCursorTimeout', 'projection', 'returnKey', 'showRecordId', 'skip', 'sort'],
9191
'createIndex' => ['keys', 'comment', 'commitQuorum', 'maxTimeMS', 'name', 'session', 'unique'],
9292
'createSearchIndex' => ['model'],
9393
'createSearchIndexes' => ['models'],
@@ -101,8 +101,8 @@ final class Util
101101
'distinct' => ['fieldName', 'filter', 'session', 'collation', 'maxTimeMS', 'comment'],
102102
'drop' => ['session', 'comment'],
103103
'dropSearchIndex' => ['name'],
104-
'find' => ['let', 'filter', 'session', 'allowDiskUse', 'allowPartialResults', 'batchSize', 'collation', 'comment', 'cursorType', 'hint', 'limit', 'max', 'maxAwaitTimeMS', 'maxScan', 'maxTimeMS', 'min', 'modifiers', 'noCursorTimeout', 'oplogReplay', 'projection', 'returnKey', 'showRecordId', 'skip', 'snapshot', 'sort'],
105-
'findOne' => ['let', 'filter', 'session', 'allowDiskUse', 'allowPartialResults', 'batchSize', 'collation', 'comment', 'cursorType', 'hint', 'max', 'maxAwaitTimeMS', 'maxScan', 'maxTimeMS', 'min', 'modifiers', 'noCursorTimeout', 'oplogReplay', 'projection', 'returnKey', 'showRecordId', 'skip', 'snapshot', 'sort'],
104+
'find' => ['let', 'filter', 'session', 'allowDiskUse', 'allowPartialResults', 'batchSize', 'collation', 'comment', 'cursorType', 'hint', 'limit', 'max', 'maxAwaitTimeMS', 'maxTimeMS', 'min', 'noCursorTimeout', 'projection', 'returnKey', 'showRecordId', 'skip', 'sort'],
105+
'findOne' => ['let', 'filter', 'session', 'allowDiskUse', 'allowPartialResults', 'batchSize', 'collation', 'comment', 'cursorType', 'hint', 'max', 'maxAwaitTimeMS', 'maxTimeMS', 'min', 'noCursorTimeout', 'projection', 'returnKey', 'showRecordId', 'skip', 'sort'],
106106
'findOneAndReplace' => ['let', 'returnDocument', 'filter', 'replacement', 'session', 'projection', 'returnDocument', 'upsert', 'arrayFilters', 'bypassDocumentValidation', 'collation', 'hint', 'maxTimeMS', 'new', 'remove', 'sort', 'comment'],
107107
'rename' => ['to', 'comment', 'dropTarget'],
108108
'replaceOne' => ['let', 'filter', 'replacement', 'session', 'upsert', 'arrayFilters', 'bypassDocumentValidation', 'collation', 'hint', 'comment'],

0 commit comments

Comments
 (0)