Unverified Commit dcd6e841 authored by Katherine Walker's avatar Katherine Walker Committed by GitHub

PHPLIB-293 Add support for a comment parameter to the aggregate command (#432)

* PHPLIB-293 Add support for a comment parameter to the aggregate command
parent 75083801
......@@ -35,6 +35,18 @@ post: |
version of MongoDB, this option will be ignored.
---
arg_name: option
name: comment
type: string
description: |
Users can specify an arbitrary string to help trace the operation through the
database profiler, currentOp, and logs.
.. versionadded:: 1.3
interface: phpmethod
operation: ~
optional: true
---
arg_name: option
name: hint
type: string|array|object
description: |
......
......@@ -74,6 +74,9 @@ class Aggregate implements Executable
* This is not supported for server versions < 3.4 and will result in an
* exception at execution time if used.
*
* * comment (string): An arbitrary string to help trace the operation
* through the database profiler, currentOp, and logs.
*
* * 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.
......@@ -150,6 +153,10 @@ class Aggregate implements Executable
throw InvalidArgumentException::invalidType('"collation" option', $options['collation'], 'array or object');
}
if (isset($options['comment']) && ! is_string($options['comment'])) {
throw InvalidArgumentException::invalidType('"comment" option', $options['comment'], 'string');
}
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');
}
......@@ -276,6 +283,12 @@ class Aggregate implements Executable
$cmd['bypassDocumentValidation'] = $this->options['bypassDocumentValidation'];
}
foreach (['comment', 'maxTimeMS'] as $option) {
if (isset($this->options[$option])) {
$cmd[$option] = $this->options[$option];
}
}
if (isset($this->options['collation'])) {
$cmd['collation'] = (object) $this->options['collation'];
}
......@@ -284,10 +297,6 @@ class Aggregate implements Executable
$cmd['hint'] = is_array($this->options['hint']) ? (object) $this->options['hint'] : $this->options['hint'];
}
if (isset($this->options['maxTimeMS'])) {
$cmd['maxTimeMS'] = $this->options['maxTimeMS'];
}
if (isset($this->options['readConcern'])) {
$cmd['readConcern'] = \MongoDB\read_concern_as_document($this->options['readConcern']);
}
......
......@@ -44,6 +44,10 @@ class AggregateTest extends TestCase
$options[][] = ['collation' => $value];
}
foreach ($this->getInvalidStringValues() as $value) {
$options[][] = ['comment' => $value];
}
foreach ($this->getInvalidHintValues() as $value) {
$options[][] = ['hint' => $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