Skip to content

Commit a2f3937

Browse files
authored
PHPLIB-721: Aggregate allowDiskUse option should be unset by default (mongodb#873)
1 parent 65d2f36 commit a2f3937

File tree

6 files changed

+26
-15
lines changed

6 files changed

+26
-15
lines changed

docs/includes/apiargs-MongoDBCollection-method-find-option.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ name: allowDiskUse
5151
type: boolean
5252
description: |
5353
Enables writing to temporary files. When set to ``true``, queries can write
54-
data to the ``_tmp`` sub-directory in the ``dbPath`` directory. The default is
55-
``false``.
54+
data to the ``_tmp`` sub-directory in the ``dbPath`` directory.
5655
interface: phpmethod
5756
operation: ~
5857
optional: true

docs/includes/apiargs-aggregate-option.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ name: allowDiskUse
33
type: boolean
44
description: |
55
Enables writing to temporary files. When set to ``true``, aggregation stages
6-
can write data to the ``_tmp`` sub-directory in the ``dbPath`` directory. The
7-
default is ``false``.
6+
can write data to the ``_tmp`` sub-directory in the ``dbPath`` directory.
87
interface: phpmethod
98
operation: ~
109
optional: true

src/Operation/Aggregate.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class Aggregate implements Executable, Explainable
8989
*
9090
* * allowDiskUse (boolean): Enables writing to temporary files. When set
9191
* to true, aggregation stages can write data to the _tmp sub-directory
92-
* in the dbPath directory. The default is false.
92+
* in the dbPath directory.
9393
*
9494
* * batchSize (integer): The number of documents to return per batch.
9595
*
@@ -179,12 +179,9 @@ public function __construct($databaseName, $collectionName, array $pipeline, arr
179179
$expectedIndex += 1;
180180
}
181181

182-
$options += [
183-
'allowDiskUse' => false,
184-
'useCursor' => true,
185-
];
182+
$options += ['useCursor' => true];
186183

187-
if (! is_bool($options['allowDiskUse'])) {
184+
if (isset($options['allowDiskUse']) && ! is_bool($options['allowDiskUse'])) {
188185
throw InvalidArgumentException::invalidType('"allowDiskUse" option', $options['allowDiskUse'], 'boolean');
189186
}
190187

@@ -363,16 +360,14 @@ private function createCommandDocument(Server $server): array
363360
'pipeline' => $this->pipeline,
364361
];
365362

366-
$cmd['allowDiskUse'] = $this->options['allowDiskUse'];
367-
368363
if (
369364
! empty($this->options['bypassDocumentValidation']) &&
370365
server_supports_feature($server, self::$wireVersionForDocumentLevelValidation)
371366
) {
372367
$cmd['bypassDocumentValidation'] = $this->options['bypassDocumentValidation'];
373368
}
374369

375-
foreach (['comment', 'explain', 'maxTimeMS'] as $option) {
370+
foreach (['allowDiskUse', 'comment', 'explain', 'maxTimeMS'] as $option) {
376371
if (isset($this->options[$option])) {
377372
$cmd[$option] = $this->options[$option];
378373
}

src/Operation/Find.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class Find implements Executable, Explainable
7979
*
8080
* * allowDiskUse (boolean): Enables writing to temporary files. When set
8181
* to true, queries can write data to the _tmp sub-directory in the
82-
* dbPath directory. The default is false.
82+
* dbPath directory.
8383
*
8484
* * allowPartialResults (boolean): Get partial results from a mongos if
8585
* some shards are inaccessible (instead of throwing an error).

tests/Operation/AggregateFunctionalTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,24 @@
1818

1919
class AggregateFunctionalTest extends FunctionalTestCase
2020
{
21+
public function testAllowDiskUseIsOmittedByDefault(): void
22+
{
23+
(new CommandObserver())->observe(
24+
function (): void {
25+
$operation = new Aggregate(
26+
$this->getDatabaseName(),
27+
$this->getCollectionName(),
28+
[['$match' => ['x' => 1]]]
29+
);
30+
31+
$operation->execute($this->getPrimaryServer());
32+
},
33+
function (array $event): void {
34+
$this->assertObjectNotHasAttribute('allowDiskUse', $event['started']->getCommand());
35+
}
36+
);
37+
}
38+
2139
public function testBatchSizeIsIgnoredIfPipelineIncludesOutStage(): void
2240
{
2341
(new CommandObserver())->observe(

tests/Operation/AggregateTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function provideInvalidConstructorOptions()
2727
{
2828
$options = [];
2929

30-
foreach ($this->getInvalidBooleanValues(true) as $value) {
30+
foreach ($this->getInvalidBooleanValues() as $value) {
3131
$options[][] = ['allowDiskUse' => $value];
3232
}
3333

0 commit comments

Comments
 (0)