Commit cfeaec21 authored by Katherine Walker's avatar Katherine Walker Committed by Katherine Walker

PHPLIB-266 Support passing index hint to aggregations

parent 929704d9
...@@ -34,6 +34,10 @@ post: | ...@@ -34,6 +34,10 @@ post: |
Document validation requires MongoDB 3.2 or later: if you are using an earlier Document validation requires MongoDB 3.2 or later: if you are using an earlier
version of MongoDB, this option will be ignored. version of MongoDB, this option will be ignored.
--- ---
source:
file: apiargs-MongoDBCollection-method-find-option.yaml
ref: hint
---
source: source:
file: apiargs-common-option.yaml file: apiargs-common-option.yaml
ref: maxTimeMS ref: maxTimeMS
......
...@@ -74,6 +74,10 @@ class Aggregate implements Executable ...@@ -74,6 +74,10 @@ class Aggregate implements Executable
* This is not supported for server versions < 3.4 and will result in an * This is not supported for server versions < 3.4 and will result in an
* exception at execution time if used. * exception at execution time if used.
* *
* * hint (string|document): The index to use. Specify either the index
* 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.
*
* * 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. * run.
* *
...@@ -146,6 +150,10 @@ class Aggregate implements Executable ...@@ -146,6 +150,10 @@ class Aggregate implements Executable
throw InvalidArgumentException::invalidType('"collation" option', $options['collation'], 'array or object'); throw InvalidArgumentException::invalidType('"collation" option', $options['collation'], 'array or object');
} }
if (isset($options['hint']) && ! is_string($options['hint']) && ! is_array($options['hint']) && ! is_object($options['hint'])) {
throw InvalidArgumentException::invalidType('"hint" option', $options['hint'], 'string or array or object');
}
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');
} }
...@@ -272,6 +280,10 @@ class Aggregate implements Executable ...@@ -272,6 +280,10 @@ class Aggregate implements Executable
$cmd['collation'] = (object) $this->options['collation']; $cmd['collation'] = (object) $this->options['collation'];
} }
if (isset($this->options['hint'])) {
$cmd['hint'] = $this->options['hint'];
}
if (isset($this->options['maxTimeMS'])) { if (isset($this->options['maxTimeMS'])) {
$cmd['maxTimeMS'] = $this->options['maxTimeMS']; $cmd['maxTimeMS'] = $this->options['maxTimeMS'];
} }
......
...@@ -44,6 +44,10 @@ class AggregateTest extends TestCase ...@@ -44,6 +44,10 @@ class AggregateTest extends TestCase
$options[][] = ['collation' => $value]; $options[][] = ['collation' => $value];
} }
foreach ($this->getInvalidHintValues() as $value) {
$options[][] = ['hint' => $value];
}
foreach ($this->getInvalidIntegerValues() as $value) { foreach ($this->getInvalidIntegerValues() as $value) {
$options[][] = ['maxTimeMS' => $value]; $options[][] = ['maxTimeMS' => $value];
} }
...@@ -98,4 +102,9 @@ class AggregateTest extends TestCase ...@@ -98,4 +102,9 @@ class AggregateTest extends TestCase
['typeMap' => ['root' => 'array'], 'useCursor' => false] ['typeMap' => ['root' => 'array'], 'useCursor' => false]
); );
} }
private function getInvalidHintValues()
{
return [123, 3.14, true];
}
} }
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