Commit 2076361e authored by Jeremy Mikola's avatar Jeremy Mikola

PHPLIB-358: Do not require collection name for Aggregate operation

parent 930fb185
...@@ -116,8 +116,11 @@ class Aggregate implements Executable ...@@ -116,8 +116,11 @@ 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.
* *
* Note: Collection-agnostic commands (e.g. $currentOp) may be executed by
* specifying null for the collection name.
*
* @param string $databaseName Database name * @param string $databaseName Database name
* @param string $collectionName Collection name * @param string|null $collectionName Collection name
* @param array $pipeline List of pipeline operations * @param array $pipeline List of pipeline operations
* @param array $options Command options * @param array $options Command options
* @throws InvalidArgumentException for parameter/option parsing errors * @throws InvalidArgumentException for parameter/option parsing errors
...@@ -220,7 +223,7 @@ class Aggregate implements Executable ...@@ -220,7 +223,7 @@ class Aggregate implements Executable
} }
$this->databaseName = (string) $databaseName; $this->databaseName = (string) $databaseName;
$this->collectionName = (string) $collectionName; $this->collectionName = isset($collectionName) ? (string) $collectionName : null;
$this->pipeline = $pipeline; $this->pipeline = $pipeline;
$this->options = $options; $this->options = $options;
} }
...@@ -289,7 +292,7 @@ class Aggregate implements Executable ...@@ -289,7 +292,7 @@ class Aggregate implements Executable
private function createCommand(Server $server) private function createCommand(Server $server)
{ {
$cmd = [ $cmd = [
'aggregate' => $this->collectionName, 'aggregate' => isset($this->collectionName) ? $this->collectionName : 1,
'pipeline' => $this->pipeline, 'pipeline' => $this->pipeline,
]; ];
$cmdOptions = []; $cmdOptions = [];
......
...@@ -12,6 +12,28 @@ use stdClass; ...@@ -12,6 +12,28 @@ use stdClass;
class AggregateFunctionalTest extends FunctionalTestCase class AggregateFunctionalTest extends FunctionalTestCase
{ {
public function testCurrentOpCommand()
{
if (version_compare($this->getServerVersion(), '3.6.0', '<')) {
$this->markTestSkipped('$currentOp is not supported');
}
(new CommandObserver)->observe(
function() {
$operation = new Aggregate(
'admin',
null,
[['$currentOp' => (object) []]]
);
$operation->execute($this->getPrimaryServer());
},
function(stdClass $command) {
$this->assertSame(1, $command->aggregate);
}
);
}
public function testDefaultReadConcernIsOmitted() public function testDefaultReadConcernIsOmitted()
{ {
(new CommandObserver)->observe( (new CommandObserver)->observe(
......
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