Skip to content

Commit 7f67f26

Browse files
committed
PHPLIB-1511: Remove deprecated query options
1 parent e746f09 commit 7f67f26

File tree

8 files changed

+10
-156
lines changed

8 files changed

+10
-156
lines changed

UPGRADE-2.0.md

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

1113
GridFS
1214
------

psalm-baseline.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -708,11 +708,7 @@
708708
<code><![CDATA[$this->options['codec']]]></code>
709709
<code><![CDATA[$this->options['typeMap']]]></code>
710710
</MixedArgument>
711-
<MixedArrayAccess>
712-
<code><![CDATA[$options['modifiers'][$modifier[1]]]]></code>
713-
</MixedArrayAccess>
714711
<MixedAssignment>
715-
<code><![CDATA[$options[$modifier[0]]]]></code>
716712
<code><![CDATA[$options[$option]]]></code>
717713
<code><![CDATA[$options['readPreference']]]></code>
718714
<code><![CDATA[$options['session']]]></code>

src/Operation/Find.php

Lines changed: 3 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
use function is_integer;
3535
use function is_object;
3636
use function is_string;
37-
use function MongoDB\document_to_array;
3837
use function MongoDB\is_document;
3938

4039
/**
@@ -88,28 +87,15 @@ final class Find implements Executable, Explainable
8887
* * maxAwaitTimeMS (integer): The maxium amount of time for the server to wait
8988
* on new documents to satisfy a query, if cursorType is TAILABLE_AWAIT.
9089
*
91-
* * maxScan (integer): Maximum number of documents or index keys to scan
92-
* when executing the query.
93-
*
94-
* This option has been deprecated since version 1.4.
95-
*
9690
* * maxTimeMS (integer): The maximum amount of time to allow the query to
97-
* run. If "$maxTimeMS" also exists in the modifiers document, this
98-
* option will take precedence.
91+
* run.
9992
*
10093
* * min (document): The inclusive upper bound for a specific index.
10194
*
102-
* * modifiers (document): Meta operators that modify the output or
103-
* behavior of a query. Use of these operators is deprecated in favor of
104-
* named options.
105-
*
10695
* * noCursorTimeout (boolean): The server normally times out idle cursors
10796
* after an inactivity period (10 minutes) to prevent excess memory use.
10897
* Set this option to prevent that.
10998
*
110-
* * oplogReplay (boolean): Internal replication use only. The driver
111-
* should not set this. This option is deprecated as of MongoDB 4.4.
112-
*
11399
* * projection (document): Limits the fields to return for the matching
114100
* document.
115101
*
@@ -128,14 +114,7 @@ final class Find implements Executable, Explainable
128114
*
129115
* * skip (integer): The number of documents to skip before returning.
130116
*
131-
* * snapshot (boolean): Prevents the cursor from returning a document more
132-
* than once because of an intervening write operation.
133-
*
134-
* This options has been deprecated since version 1.4.
135-
*
136-
* * sort (document): The order in which to return matching documents. If
137-
* "$orderby" also exists in the modifiers document, this option will
138-
* take precedence.
117+
* * sort (document): The order in which to return matching documents.
139118
*
140119
* * let (document): Map of parameter names and values. Values must be
141120
* constant or closed expressions that do not reference document fields.
@@ -207,10 +186,6 @@ public function __construct(private string $databaseName, private string $collec
207186
throw InvalidArgumentException::invalidType('"maxAwaitTimeMS" option', $this->options['maxAwaitTimeMS'], 'integer');
208187
}
209188

210-
if (isset($this->options['maxScan']) && ! is_integer($this->options['maxScan'])) {
211-
throw InvalidArgumentException::invalidType('"maxScan" option', $this->options['maxScan'], 'integer');
212-
}
213-
214189
if (isset($this->options['maxTimeMS']) && ! is_integer($this->options['maxTimeMS'])) {
215190
throw InvalidArgumentException::invalidType('"maxTimeMS" option', $this->options['maxTimeMS'], 'integer');
216191
}
@@ -219,18 +194,10 @@ public function __construct(private string $databaseName, private string $collec
219194
throw InvalidArgumentException::expectedDocumentType('"min" option', $this->options['min']);
220195
}
221196

222-
if (isset($this->options['modifiers']) && ! is_document($this->options['modifiers'])) {
223-
throw InvalidArgumentException::expectedDocumentType('"modifiers" option', $this->options['modifiers']);
224-
}
225-
226197
if (isset($this->options['noCursorTimeout']) && ! is_bool($this->options['noCursorTimeout'])) {
227198
throw InvalidArgumentException::invalidType('"noCursorTimeout" option', $this->options['noCursorTimeout'], 'boolean');
228199
}
229200

230-
if (isset($this->options['oplogReplay']) && ! is_bool($this->options['oplogReplay'])) {
231-
throw InvalidArgumentException::invalidType('"oplogReplay" option', $this->options['oplogReplay'], 'boolean');
232-
}
233-
234201
if (isset($this->options['projection']) && ! is_document($this->options['projection'])) {
235202
throw InvalidArgumentException::expectedDocumentType('"projection" option', $this->options['projection']);
236203
}
@@ -259,10 +226,6 @@ public function __construct(private string $databaseName, private string $collec
259226
throw InvalidArgumentException::invalidType('"skip" option', $this->options['skip'], 'integer');
260227
}
261228

262-
if (isset($this->options['snapshot']) && ! is_bool($this->options['snapshot'])) {
263-
throw InvalidArgumentException::invalidType('"snapshot" option', $this->options['snapshot'], 'boolean');
264-
}
265-
266229
if (isset($this->options['sort']) && ! is_document($this->options['sort'])) {
267230
throw InvalidArgumentException::expectedDocumentType('"sort" option', $this->options['sort']);
268231
}
@@ -329,28 +292,6 @@ public function getCommandDocument(): array
329292
// maxAwaitTimeMS is a Query level option so should not be considered here
330293
unset($options['maxAwaitTimeMS']);
331294

332-
$modifierFallback = [
333-
['allowPartialResults', 'partial'],
334-
['comment', '$comment'],
335-
['hint', '$hint'],
336-
['maxScan', '$maxScan'],
337-
['max', '$max'],
338-
['maxTimeMS', '$maxTimeMS'],
339-
['min', '$min'],
340-
['returnKey', '$returnKey'],
341-
['showRecordId', '$showDiskLoc'],
342-
['sort', '$orderby'],
343-
['snapshot', '$snapshot'],
344-
];
345-
346-
foreach ($modifierFallback as $modifier) {
347-
if (! isset($options[$modifier[0]]) && isset($options['modifiers'][$modifier[1]])) {
348-
$options[$modifier[0]] = $options['modifiers'][$modifier[1]];
349-
}
350-
}
351-
352-
unset($options['modifiers']);
353-
354295
return $cmd + $options;
355296
}
356297

@@ -395,7 +336,7 @@ private function createQueryOptions(): array
395336
}
396337
}
397338

398-
foreach (['allowDiskUse', 'allowPartialResults', 'batchSize', 'comment', 'hint', 'limit', 'maxAwaitTimeMS', 'maxScan', 'maxTimeMS', 'noCursorTimeout', 'oplogReplay', 'projection', 'readConcern', 'returnKey', 'showRecordId', 'skip', 'snapshot', 'sort'] as $option) {
339+
foreach (['allowDiskUse', 'allowPartialResults', 'batchSize', 'comment', 'hint', 'limit', 'maxAwaitTimeMS', 'maxTimeMS', 'noCursorTimeout', 'projection', 'readConcern', 'returnKey', 'showRecordId', 'skip', 'sort'] as $option) {
399340
if (isset($this->options[$option])) {
400341
$options[$option] = $this->options[$option];
401342
}
@@ -407,12 +348,6 @@ private function createQueryOptions(): array
407348
}
408349
}
409350

410-
if (! empty($this->options['modifiers'])) {
411-
/** @psalm-var array|object */
412-
$modifiers = $this->options['modifiers'];
413-
$options['modifiers'] = is_object($modifiers) ? document_to_array($modifiers) : $modifiers;
414-
}
415-
416351
return $options;
417352
}
418353
}

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 & 36 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,40 +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-
$this->assertDeprecated(
52-
fn () => $operation->execute($this->getPrimaryServer()),
53-
);
54-
},
55-
function (array $event) use ($expectedSort): void {
56-
$this->assertEquals($expectedSort, $event['started']->getCommand()->sort ?? null);
57-
},
58-
);
59-
}
60-
61-
public static function provideModifierDocuments(): array
62-
{
63-
$expectedSort = (object) ['x' => 1];
64-
65-
return [
66-
'array' => [['$orderby' => ['x' => 1]], $expectedSort],
67-
'object' => [(object) ['$orderby' => ['x' => 1]], $expectedSort],
68-
'Serializable' => [new BSONDocument(['$orderby' => ['x' => 1]]), $expectedSort],
69-
'Document' => [Document::fromPHP(['$orderby' => ['x' => 1]]), $expectedSort],
70-
];
71-
}
72-
7337
public function testDefaultReadConcernIsOmitted(): void
7438
{
7539
(new CommandObserver())->observe(

tests/Operation/FindTest.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,15 @@ 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
]);
@@ -69,7 +65,6 @@ public static function provideInvalidConstructorCursorTypeOptions()
6965

7066
public function testExplainableCommandDocument(): void
7167
{
72-
// all options except deprecated "snapshot" and "maxScan"
7368
$options = [
7469
'allowDiskUse' => true,
7570
'allowPartialResults' => true,
@@ -82,7 +77,6 @@ public function testExplainableCommandDocument(): void
8277
'maxTimeMS' => 100,
8378
'min' => ['x' => 10],
8479
'noCursorTimeout' => true,
85-
'oplogReplay' => true,
8680
'projection' => ['_id' => 0],
8781
'readConcern' => new ReadConcern(ReadConcern::LOCAL),
8882
'returnKey' => true,
@@ -93,7 +87,6 @@ public function testExplainableCommandDocument(): void
9387
// Intentionally omitted options
9488
'cursorType' => Find::NON_TAILABLE,
9589
'maxAwaitTimeMS' => 500,
96-
'modifiers' => ['foo' => 'bar'],
9790
'readPreference' => new ReadPreference(ReadPreference::SECONDARY_PREFERRED),
9891
'typeMap' => ['root' => 'array'],
9992
];
@@ -110,7 +103,6 @@ public function testExplainableCommandDocument(): void
110103
'limit' => 15,
111104
'maxTimeMS' => 100,
112105
'noCursorTimeout' => true,
113-
'oplogReplay' => true,
114106
'projection' => ['_id' => 0],
115107
'readConcern' => new ReadConcern(ReadConcern::LOCAL),
116108
'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)