Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! I just came across #423 while looking through closed PRs and was going to pop in to ask about this, but you beat me to it 👍

interface: phpmethod
operation: ~
optional: true
---
arg_name: option
name: hint
type: string|array|object
description: |
Expand Down
17 changes: 13 additions & 4 deletions src/Operation/Aggregate.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -150,6 +153,10 @@ public function __construct($databaseName, $collectionName, array $pipeline, arr
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');
}
Expand Down Expand Up @@ -276,6 +283,12 @@ private function createCommand(Server $server, $isCursorSupported)
$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'];
}
Expand All @@ -284,10 +297,6 @@ private function createCommand(Server $server, $isCursorSupported)
$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']);
}
Expand Down
4 changes: 4 additions & 0 deletions tests/Operation/AggregateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ public function provideInvalidConstructorOptions()
$options[][] = ['collation' => $value];
}

foreach ($this->getInvalidStringValues() as $value) {
$options[][] = ['comment' => $value];
}

foreach ($this->getInvalidHintValues() as $value) {
$options[][] = ['hint' => $value];
}
Expand Down