Skip to content

Commit c7728da

Browse files
committed
PHPLIB-1511: Remove deprecated query options
1 parent 40c95c5 commit c7728da

File tree

8 files changed

+10
-183
lines changed

8 files changed

+10
-183
lines changed

UPGRADE-2.0.md

+2
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

-4
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

+3-79
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,7 @@
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;
39-
use function trigger_error;
40-
41-
use const E_USER_DEPRECATED;
4238

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

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

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

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

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

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

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

@@ -406,7 +336,7 @@ private function createQueryOptions(): array
406336
}
407337
}
408338

409-
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) {
410340
if (isset($this->options[$option])) {
411341
$options[$option] = $this->options[$option];
412342
}
@@ -418,12 +348,6 @@ private function createQueryOptions(): array
418348
}
419349
}
420350

421-
if (! empty($this->options['modifiers'])) {
422-
/** @psalm-var array|object */
423-
$modifiers = $this->options['modifiers'];
424-
$options['modifiers'] = is_object($modifiers) ? document_to_array($modifiers) : $modifiers;
425-
}
426-
427351
return $options;
428352
}
429353
}

src/Operation/FindOne.php

+2-13
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

-24
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

-34
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

-26
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

+3-3
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)