PHPLIB-500: Support for allowDiskUse on find operations

parent 68d49083
......@@ -47,6 +47,17 @@ operation: ~
optional: true
---
arg_name: option
name: allowDiskUse
type: boolean
description: |
Enables writing to temporary files. When set to ``true``, queries can write
data to the ``_tmp`` sub-directory in the ``dbPath`` directory. The default is
``false``.
interface: phpmethod
operation: ~
optional: true
---
arg_name: option
name: batchSize
type: integer
description: |
......
......@@ -10,6 +10,10 @@ source:
file: apiargs-MongoDBCollection-method-find-option.yaml
ref: skip
---
source:
file: apiargs-MongoDBCollection-method-find-option.yaml
ref: allowDiskUse
---
source:
file: apiargs-MongoDBCollection-common-option.yaml
ref: collation
......
......@@ -14,6 +14,10 @@ source:
file: apiargs-MongoDBCollection-method-find-option.yaml
ref: limit
---
source:
file: apiargs-MongoDBCollection-method-find-option.yaml
ref: allowDiskUse
---
source:
file: apiargs-MongoDBCollection-method-find-option.yaml
ref: batchSize
......
......@@ -10,6 +10,10 @@ source:
file: apiargs-MongoDBCollection-method-find-option.yaml
ref: skip
---
source:
file: apiargs-MongoDBCollection-method-find-option.yaml
ref: allowDiskUse
---
source:
file: apiargs-MongoDBCollection-common-option.yaml
ref: collation
......
......@@ -72,6 +72,10 @@ class Find implements Executable, Explainable
*
* Supported options:
*
* * allowDiskUse (boolean): Enables writing to temporary files. When set
* to true, queries can write data to the _tmp sub-directory in the
* dbPath directory. The default is false.
*
* * allowPartialResults (boolean): Get partial results from a mongos if
* some shards are inaccessible (instead of throwing an error).
*
......@@ -169,6 +173,10 @@ class Find implements Executable, Explainable
throw InvalidArgumentException::invalidType('$filter', $filter, 'array or object');
}
if (isset($options['allowDiskUse']) && ! is_bool($options['allowDiskUse'])) {
throw InvalidArgumentException::invalidType('"allowDiskUse" option', $options['allowDiskUse'], 'boolean');
}
if (isset($options['allowPartialResults']) && ! is_bool($options['allowPartialResults'])) {
throw InvalidArgumentException::invalidType('"allowPartialResults" option', $options['allowPartialResults'], 'boolean');
}
......@@ -416,7 +424,7 @@ class Find implements Executable, Explainable
}
}
foreach (['allowPartialResults', 'batchSize', 'comment', 'hint', 'limit', 'maxAwaitTimeMS', 'maxScan', 'maxTimeMS', 'noCursorTimeout', 'oplogReplay', 'projection', 'readConcern', 'returnKey', 'showRecordId', 'skip', 'snapshot', 'sort'] as $option) {
foreach (['allowDiskUse', 'allowPartialResults', 'batchSize', 'comment', 'hint', 'limit', 'maxAwaitTimeMS', 'maxScan', 'maxTimeMS', 'noCursorTimeout', 'oplogReplay', 'projection', 'readConcern', 'returnKey', 'showRecordId', 'skip', 'snapshot', 'sort'] as $option) {
if (isset($this->options[$option])) {
$options[$option] = $this->options[$option];
}
......
......@@ -15,11 +15,7 @@ use function glob;
class CrudSpecTest extends FunctionalTestCase
{
/** @var array */
private static $incompleteTests = [
'find-allowdiskuse: Find does not send allowDiskuse when value is not specified' => 'PHPLIB-500',
'find-allowdiskuse: Find sends allowDiskuse false when false is specified' => 'PHPLIB-500',
'find-allowdiskuse: Find sends allowDiskUse true when true is specified' => 'PHPLIB-500',
];
private static $incompleteTests = [];
/**
* Assert that the expected and actual command documents match.
......@@ -29,6 +25,13 @@ class CrudSpecTest extends FunctionalTestCase
*/
public static function assertCommandMatches(stdClass $expected, stdClass $actual)
{
foreach ($expected as $key => $value) {
if ($value === null) {
static::assertObjectNotHasAttribute($key, $actual);
unset($expected->{$key});
}
}
static::assertDocumentsMatch($expected, $actual);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment