Commit 202bef69 authored by Jeremy Mikola's avatar Jeremy Mikola

PHPLIB-287: Add named modifier options to Find and FindOne

Before PHPC 1.2.0, these options could only be specified as query modifiers.
parent d960f5f9
...@@ -106,6 +106,39 @@ source: ...@@ -106,6 +106,39 @@ source:
ref: readPreference ref: readPreference
--- ---
arg_name: option arg_name: option
name: max
type: array|object
description: |
The exclusive upper bound for a specific index.
.. versionadded:: 1.2
interface: phpmethod
operation: ~
optional: true
---
arg_name: option
name: maxScan
type: integer
description: |
Maximum number of documents or index keys to scan when executing the query.
.. versionadded:: 1.2
interface: phpmethod
operation: ~
optional: true
---
arg_name: option
name: min
type: array|object
description: |
The inclusive lower bound for a specific index.
.. versionadded:: 1.2
interface: phpmethod
operation: ~
optional: true
---
arg_name: option
name: oplogReplay name: oplogReplay
type: boolean type: boolean
description: | description: |
...@@ -133,6 +166,41 @@ operation: ~ ...@@ -133,6 +166,41 @@ operation: ~
optional: true optional: true
--- ---
arg_name: option arg_name: option
name: returnKey
type: boolean
description: |
If true, returns only the index keys in the resulting documents.
.. versionadded:: 1.2
interface: phpmethod
operation: ~
optional: true
---
arg_name: option
name: showRecordId
type: boolean
description: |
Determines whether to return the record identifier for each document. If true,
adds a field $recordId to the returned documents.
.. versionadded:: 1.2
interface: phpmethod
operation: ~
optional: true
---
arg_name: option
name: snapshot
type: boolean
description: |
Prevents the cursor from returning a document more than once because of an
intervening write operation.
.. versionadded:: 1.2
interface: phpmethod
operation: ~
optional: true
---
arg_name: option
name: allowPartialResults name: allowPartialResults
type: boolean type: boolean
description: | description: |
......
...@@ -40,6 +40,26 @@ source: ...@@ -40,6 +40,26 @@ source:
post: | post: |
This will be used for the returned result document. This will be used for the returned result document.
--- ---
source:
file: apiargs-MongoDBCollection-method-find-option.yaml
ref: max
---
source:
file: apiargs-MongoDBCollection-method-find-option.yaml
ref: maxScan
---
source:
file: apiargs-MongoDBCollection-method-find-option.yaml
ref: min
---
source:
file: apiargs-MongoDBCollection-method-find-option.yaml
ref: returnKey
---
source:
file: apiargs-MongoDBCollection-method-find-option.yaml
ref: showRecordId
---
source: source:
file: apiargs-MongoDBCollection-method-find-option.yaml file: apiargs-MongoDBCollection-method-find-option.yaml
ref: modifiers ref: modifiers
......
...@@ -76,10 +76,17 @@ class Find implements Executable ...@@ -76,10 +76,17 @@ class Find implements Executable
* *
* * limit (integer): The maximum number of documents to return. * * limit (integer): The maximum number of documents to return.
* *
* * max (document): The exclusive upper bound for a specific index.
*
* * maxScan (integer): Maximum number of documents or index keys to scan
* when executing the query.
*
* * maxTimeMS (integer): The maximum amount of time to allow the query to * * maxTimeMS (integer): The maximum amount of time to allow the query to
* run. If "$maxTimeMS" also exists in the modifiers document, this * run. If "$maxTimeMS" also exists in the modifiers document, this
* option will take precedence. * option will take precedence.
* *
* * min (document): The inclusive upper bound for a specific index.
*
* * modifiers (document): Meta operators that modify the output or * * modifiers (document): Meta operators that modify the output or
* behavior of a query. Use of these operators is deprecated in favor of * behavior of a query. Use of these operators is deprecated in favor of
* named options. * named options.
...@@ -101,8 +108,18 @@ class Find implements Executable ...@@ -101,8 +108,18 @@ class Find implements Executable
* *
* * readPreference (MongoDB\Driver\ReadPreference): Read preference. * * readPreference (MongoDB\Driver\ReadPreference): Read preference.
* *
* * returnKey (boolean): If true, returns only the index keys in the
* resulting documents.
*
* * showRecordId (boolean): Determines whether to return the record
* identifier for each document. If true, adds a field $recordId to the
* returned documents.
*
* * skip (integer): The number of documents to skip before returning. * * skip (integer): The number of documents to skip before returning.
* *
* * snapshot (boolean): Prevents the cursor from returning a document more
* than once because of an intervening write operation.
*
* * sort (document): The order in which to return matching documents. If * * sort (document): The order in which to return matching documents. If
* "$orderby" also exists in the modifiers document, this option will * "$orderby" also exists in the modifiers document, this option will
* take precedence. * take precedence.
...@@ -158,10 +175,22 @@ class Find implements Executable ...@@ -158,10 +175,22 @@ class Find implements Executable
throw InvalidArgumentException::invalidType('"limit" option', $options['limit'], 'integer'); throw InvalidArgumentException::invalidType('"limit" option', $options['limit'], 'integer');
} }
if (isset($options['max']) && ! is_array($options['max']) && ! is_object($options['max'])) {
throw InvalidArgumentException::invalidType('"max" option', $options['max'], 'array or object');
}
if (isset($options['maxScan']) && ! is_integer($options['maxScan'])) {
throw InvalidArgumentException::invalidType('"maxScan" option', $options['maxScan'], 'integer');
}
if (isset($options['maxTimeMS']) && ! is_integer($options['maxTimeMS'])) { if (isset($options['maxTimeMS']) && ! is_integer($options['maxTimeMS'])) {
throw InvalidArgumentException::invalidType('"maxTimeMS" option', $options['maxTimeMS'], 'integer'); throw InvalidArgumentException::invalidType('"maxTimeMS" option', $options['maxTimeMS'], 'integer');
} }
if (isset($options['min']) && ! is_array($options['min']) && ! is_object($options['min'])) {
throw InvalidArgumentException::invalidType('"min" option', $options['min'], 'array or object');
}
if (isset($options['modifiers']) && ! is_array($options['modifiers']) && ! is_object($options['modifiers'])) { if (isset($options['modifiers']) && ! is_array($options['modifiers']) && ! is_object($options['modifiers'])) {
throw InvalidArgumentException::invalidType('"modifiers" option', $options['modifiers'], 'array or object'); throw InvalidArgumentException::invalidType('"modifiers" option', $options['modifiers'], 'array or object');
} }
...@@ -186,10 +215,22 @@ class Find implements Executable ...@@ -186,10 +215,22 @@ class Find implements Executable
throw InvalidArgumentException::invalidType('"readPreference" option', $options['readPreference'], 'MongoDB\Driver\ReadPreference'); throw InvalidArgumentException::invalidType('"readPreference" option', $options['readPreference'], 'MongoDB\Driver\ReadPreference');
} }
if (isset($options['returnKey']) && ! is_bool($options['returnKey'])) {
throw InvalidArgumentException::invalidType('"returnKey" option', $options['returnKey'], 'boolean');
}
if (isset($options['showRecordId']) && ! is_bool($options['showRecordId'])) {
throw InvalidArgumentException::invalidType('"showRecordId" option', $options['showRecordId'], 'boolean');
}
if (isset($options['skip']) && ! is_integer($options['skip'])) { if (isset($options['skip']) && ! is_integer($options['skip'])) {
throw InvalidArgumentException::invalidType('"skip" option', $options['skip'], 'integer'); throw InvalidArgumentException::invalidType('"skip" option', $options['skip'], 'integer');
} }
if (isset($options['snapshot']) && ! is_bool($options['snapshot'])) {
throw InvalidArgumentException::invalidType('"snapshot" option', $options['snapshot'], 'boolean');
}
if (isset($options['sort']) && ! is_array($options['sort']) && ! is_object($options['sort'])) { if (isset($options['sort']) && ! is_array($options['sort']) && ! is_object($options['sort'])) {
throw InvalidArgumentException::invalidType('"sort" option', $options['sort'], 'array or object'); throw InvalidArgumentException::invalidType('"sort" option', $options['sort'], 'array or object');
} }
...@@ -257,14 +298,16 @@ class Find implements Executable ...@@ -257,14 +298,16 @@ class Find implements Executable
} }
} }
foreach (['allowPartialResults', 'batchSize', 'comment', 'hint', 'limit', 'maxTimeMS', 'noCursorTimeout', 'oplogReplay', 'projection', 'readConcern', 'skip', 'sort'] as $option) { foreach (['allowPartialResults', 'batchSize', 'comment', 'hint', 'limit', 'maxScan', 'maxTimeMS', 'noCursorTimeout', 'oplogReplay', 'projection', 'readConcern', 'returnKey', 'showRecordId', 'skip', 'snapshot', 'sort'] as $option) {
if (isset($this->options[$option])) { if (isset($this->options[$option])) {
$options[$option] = $this->options[$option]; $options[$option] = $this->options[$option];
} }
} }
if (isset($this->options['collation'])) { foreach (['collation', 'max', 'min'] as $option) {
$options['collation'] = (object) $this->options['collation']; if (isset($this->options[$option])) {
$options[$option] = (object) $this->options[$option];
}
} }
$modifiers = empty($this->options['modifiers']) ? [] : (array) $this->options['modifiers']; $modifiers = empty($this->options['modifiers']) ? [] : (array) $this->options['modifiers'];
......
...@@ -52,10 +52,17 @@ class FindOne implements Executable ...@@ -52,10 +52,17 @@ class FindOne implements Executable
* name as a string or the index key pattern as a document. If specified, * name as a string or the index key pattern as a document. If specified,
* then the query system will only consider plans using the hinted index. * then the query system will only consider plans using the hinted index.
* *
* * max (document): The exclusive upper bound for a specific index.
*
* * maxScan (integer): Maximum number of documents or index keys to scan
* when executing the query.
*
* * maxTimeMS (integer): The maximum amount of time to allow the query to * * maxTimeMS (integer): The maximum amount of time to allow the query to
* run. If "$maxTimeMS" also exists in the modifiers document, this * run. If "$maxTimeMS" also exists in the modifiers document, this
* option will take precedence. * option will take precedence.
* *
* * min (document): The inclusive upper bound for a specific index.
*
* * modifiers (document): Meta-operators modifying the output or behavior * * modifiers (document): Meta-operators modifying the output or behavior
* of a query. * of a query.
* *
...@@ -69,6 +76,13 @@ class FindOne implements Executable ...@@ -69,6 +76,13 @@ class FindOne implements Executable
* *
* * readPreference (MongoDB\Driver\ReadPreference): Read preference. * * readPreference (MongoDB\Driver\ReadPreference): Read preference.
* *
* * returnKey (boolean): If true, returns only the index keys in the
* resulting documents.
*
* * showRecordId (boolean): Determines whether to return the record
* identifier for each document. If true, adds a field $recordId to the
* returned documents.
*
* * skip (integer): The number of documents to skip before returning. * * skip (integer): The number of documents to skip before returning.
* *
* * sort (document): The order in which to return matching documents. If * * sort (document): The order in which to return matching documents. If
......
...@@ -56,10 +56,22 @@ class FindTest extends TestCase ...@@ -56,10 +56,22 @@ class FindTest extends TestCase
$options[][] = ['limit' => $value]; $options[][] = ['limit' => $value];
} }
foreach ($this->getInvalidDocumentValues() as $value) {
$options[][] = ['max' => $value];
}
foreach ($this->getInvalidIntegerValues() as $value) {
$options[][] = ['maxScan' => $value];
}
foreach ($this->getInvalidIntegerValues() as $value) { foreach ($this->getInvalidIntegerValues() as $value) {
$options[][] = ['maxTimeMS' => $value]; $options[][] = ['maxTimeMS' => $value];
} }
foreach ($this->getInvalidDocumentValues() as $value) {
$options[][] = ['min' => $value];
}
foreach ($this->getInvalidDocumentValues() as $value) { foreach ($this->getInvalidDocumentValues() as $value) {
$options[][] = ['modifiers' => $value]; $options[][] = ['modifiers' => $value];
} }
...@@ -80,10 +92,22 @@ class FindTest extends TestCase ...@@ -80,10 +92,22 @@ class FindTest extends TestCase
$options[][] = ['readPreference' => $value]; $options[][] = ['readPreference' => $value];
} }
foreach ($this->getInvalidBooleanValues() as $value) {
$options[][] = ['returnKey' => $value];
}
foreach ($this->getInvalidBooleanValues() as $value) {
$options[][] = ['showRecordId' => $value];
}
foreach ($this->getInvalidIntegerValues() as $value) { foreach ($this->getInvalidIntegerValues() as $value) {
$options[][] = ['skip' => $value]; $options[][] = ['skip' => $value];
} }
foreach ($this->getInvalidBooleanValues() as $value) {
$options[][] = ['snapshot' => $value];
}
foreach ($this->getInvalidDocumentValues() as $value) { foreach ($this->getInvalidDocumentValues() as $value) {
$options[][] = ['sort' => $value]; $options[][] = ['sort' => $value];
} }
......
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