Skip to content

Commit 405660f

Browse files
committed
PHPLIB-1511: Remove deprecated query options
1 parent a139f48 commit 405660f

File tree

8 files changed

+10
-162
lines changed

8 files changed

+10
-162
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
@@ -158,30 +158,6 @@ function (array $event): void {
158158
);
159159
}
160160

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

tests/Operation/FindFunctionalTest.php

Lines changed: 0 additions & 42 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;
@@ -14,7 +12,6 @@
1412
use PHPUnit\Framework\Attributes\DataProvider;
1513
use stdClass;
1614

17-
use function is_array;
1815
use function microtime;
1916

2017
class FindFunctionalTest extends FunctionalTestCase
@@ -38,45 +35,6 @@ function (array $event) use ($expectedQuery): void {
3835
);
3936
}
4037

41-
#[DataProvider('provideModifierDocuments')]
42-
public function testModifierDocuments($modifiers, stdClass $expectedSort): void
43-
{
44-
(new CommandObserver())->observe(
45-
function () use ($modifiers): void {
46-
// @todo revert this lines after PHPC-2457
47-
if (is_array($modifiers)) {
48-
$modifiers = [...$modifiers];
49-
}
50-
51-
$operation = new Find(
52-
$this->getDatabaseName(),
53-
$this->getCollectionName(),
54-
[],
55-
['modifiers' => $modifiers],
56-
);
57-
58-
$this->assertDeprecated(
59-
fn () => $operation->execute($this->getPrimaryServer()),
60-
);
61-
},
62-
function (array $event) use ($expectedSort): void {
63-
$this->assertEquals($expectedSort, $event['started']->getCommand()->sort ?? null);
64-
},
65-
);
66-
}
67-
68-
public static function provideModifierDocuments(): array
69-
{
70-
$expectedSort = (object) ['x' => 1];
71-
72-
return [
73-
'array' => [['$orderby' => ['x' => 1]], $expectedSort],
74-
'object' => [(object) ['$orderby' => ['x' => 1]], $expectedSort],
75-
'Serializable' => [new BSONDocument(['$orderby' => ['x' => 1]]), $expectedSort],
76-
'Document' => [Document::fromPHP(['$orderby' => ['x' => 1]]), $expectedSort],
77-
];
78-
}
79-
8038
public function testDefaultReadConcernIsOmitted(): void
8139
{
8240
(new CommandObserver())->observe(

tests/Operation/FindTest.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,15 @@ public static function provideInvalidConstructorOptions()
3838
'limit' => self::getInvalidIntegerValues(),
3939
'max' => self::getInvalidDocumentValues(),
4040
'maxAwaitTimeMS' => self::getInvalidIntegerValues(),
41-
'maxScan' => self::getInvalidIntegerValues(),
4241
'maxTimeMS' => self::getInvalidIntegerValues(),
4342
'min' => self::getInvalidDocumentValues(),
44-
'modifiers' => self::getInvalidDocumentValues(),
45-
'oplogReplay' => self::getInvalidBooleanValues(),
4643
'projection' => self::getInvalidDocumentValues(),
4744
'readConcern' => self::getInvalidReadConcernValues(),
4845
'readPreference' => self::getInvalidReadPreferenceValues(),
4946
'returnKey' => self::getInvalidBooleanValues(),
5047
'session' => self::getInvalidSessionValues(),
5148
'showRecordId' => self::getInvalidBooleanValues(),
5249
'skip' => self::getInvalidIntegerValues(),
53-
'snapshot' => self::getInvalidBooleanValues(),
5450
'sort' => self::getInvalidDocumentValues(),
5551
'typeMap' => self::getInvalidArrayValues(),
5652
]);
@@ -70,7 +66,6 @@ public static function provideInvalidConstructorCursorTypeOptions()
7066

7167
public function testExplainableCommandDocument(): void
7268
{
73-
// all options except deprecated "snapshot" and "maxScan"
7469
$options = [
7570
'allowDiskUse' => true,
7671
'allowPartialResults' => true,
@@ -83,7 +78,6 @@ public function testExplainableCommandDocument(): void
8378
'maxTimeMS' => 100,
8479
'min' => ['x' => 10],
8580
'noCursorTimeout' => true,
86-
'oplogReplay' => true,
8781
'projection' => ['_id' => 0],
8882
'readConcern' => new ReadConcern(ReadConcern::LOCAL),
8983
'returnKey' => true,
@@ -94,7 +88,6 @@ public function testExplainableCommandDocument(): void
9488
// Intentionally omitted options
9589
'cursorType' => Find::NON_TAILABLE,
9690
'maxAwaitTimeMS' => 500,
97-
'modifiers' => ['foo' => 'bar'],
9891
'readPreference' => new ReadPreference(ReadPreference::SECONDARY_PREFERRED),
9992
'typeMap' => ['root' => 'array'],
10093
];
@@ -111,7 +104,6 @@ public function testExplainableCommandDocument(): void
111104
'limit' => 15,
112105
'maxTimeMS' => 100,
113106
'noCursorTimeout' => true,
114-
'oplogReplay' => true,
115107
'projection' => ['_id' => 0],
116108
'readConcern' => new ReadConcern(ReadConcern::LOCAL),
117109
'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)