Commit 6ecf84a8 authored by Jeremy Mikola's avatar Jeremy Mikola

Merge pull request #592

parents a452dd8b 39fa0115
...@@ -255,7 +255,7 @@ class Aggregate implements Executable ...@@ -255,7 +255,7 @@ class Aggregate implements Executable
$hasExplain = ! empty($this->options['explain']); $hasExplain = ! empty($this->options['explain']);
$hasOutStage = \MongoDB\is_last_pipeline_operator_out($this->pipeline); $hasOutStage = \MongoDB\is_last_pipeline_operator_out($this->pipeline);
$command = $this->createCommand($server); $command = $this->createCommand($server, $hasOutStage);
$options = $this->createOptions($hasOutStage, $hasExplain); $options = $this->createOptions($hasOutStage, $hasExplain);
$cursor = ($hasOutStage && ! $hasExplain) $cursor = ($hasOutStage && ! $hasExplain)
...@@ -287,9 +287,10 @@ class Aggregate implements Executable ...@@ -287,9 +287,10 @@ class Aggregate implements Executable
* Create the aggregate command. * Create the aggregate command.
* *
* @param Server $server * @param Server $server
* @param boolean $hasOutStage
* @return Command * @return Command
*/ */
private function createCommand(Server $server) private function createCommand(Server $server, $hasOutStage)
{ {
$cmd = [ $cmd = [
'aggregate' => isset($this->collectionName) ? $this->collectionName : 1, 'aggregate' => isset($this->collectionName) ? $this->collectionName : 1,
...@@ -325,7 +326,10 @@ class Aggregate implements Executable ...@@ -325,7 +326,10 @@ class Aggregate implements Executable
} }
if ($this->options['useCursor']) { if ($this->options['useCursor']) {
$cmd['cursor'] = isset($this->options["batchSize"]) /* Ignore batchSize if pipeline includes an $out stage, as no
* documents will be returned and sending a batchSize of zero could
* prevent the pipeline from executing at all. */
$cmd['cursor'] = isset($this->options["batchSize"]) && ! $hasOutStage
? ['batchSize' => $this->options["batchSize"]] ? ['batchSize' => $this->options["batchSize"]]
: new stdClass; : new stdClass;
} }
......
...@@ -43,6 +43,11 @@ class CrudSpecFunctionalTest extends FunctionalTestCase ...@@ -43,6 +43,11 @@ class CrudSpecFunctionalTest extends FunctionalTestCase
$expectedData = isset($test['outcome']['collection']['data']) ? $test['outcome']['collection']['data'] : null; $expectedData = isset($test['outcome']['collection']['data']) ? $test['outcome']['collection']['data'] : null;
$this->initializeData($initialData, $expectedData); $this->initializeData($initialData, $expectedData);
if (isset($test['outcome']['collection']['name'])) {
$outputCollection = new Collection($this->manager, $this->getDatabaseName(), $test['outcome']['collection']['name']);
$outputCollection->drop();
}
$result = null; $result = null;
$exception = null; $exception = null;
...@@ -81,7 +86,7 @@ class CrudSpecFunctionalTest extends FunctionalTestCase ...@@ -81,7 +86,7 @@ class CrudSpecFunctionalTest extends FunctionalTestCase
*/ */
private function assertEquivalentCollections($expectedCollection, $actualCollection) private function assertEquivalentCollections($expectedCollection, $actualCollection)
{ {
$mi = new MultipleIterator; $mi = new MultipleIterator(MultipleIterator::MIT_NEED_ANY);
$mi->attachIterator(new IteratorIterator($expectedCollection->find())); $mi->attachIterator(new IteratorIterator($expectedCollection->find()));
$mi->attachIterator(new IteratorIterator($actualCollection->find())); $mi->attachIterator(new IteratorIterator($actualCollection->find()));
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace MongoDB\Tests\Operation; namespace MongoDB\Tests\Operation;
use MongoDB\Collection;
use MongoDB\Driver\BulkWrite; use MongoDB\Driver\BulkWrite;
use MongoDB\Driver\ReadPreference; use MongoDB\Driver\ReadPreference;
use MongoDB\Driver\WriteConcern; use MongoDB\Driver\WriteConcern;
...@@ -14,6 +15,28 @@ use stdClass; ...@@ -14,6 +15,28 @@ use stdClass;
class AggregateFunctionalTest extends FunctionalTestCase class AggregateFunctionalTest extends FunctionalTestCase
{ {
public function testBatchSizeIsIgnoredIfPipelineIncludesOutStage()
{
(new CommandObserver)->observe(
function() {
$operation = new Aggregate(
$this->getDatabaseName(),
$this->getCollectionName(),
[['$out' => $this->getCollectionName() . '.output']],
['batchSize' => 0]
);
$operation->execute($this->getPrimaryServer());
},
function(array $event) {
$this->assertEquals(new stdClass, $event['started']->getCommand()->cursor);
}
);
$outCollection = new Collection($this->manager, $this->getDatabaseName(), $this->getCollectionName() . '.output');
$outCollection->drop();
}
public function testCurrentOpCommand() public function testCurrentOpCommand()
{ {
if (version_compare($this->getServerVersion(), '3.6.0', '<')) { if (version_compare($this->getServerVersion(), '3.6.0', '<')) {
...@@ -72,6 +95,9 @@ class AggregateFunctionalTest extends FunctionalTestCase ...@@ -72,6 +95,9 @@ class AggregateFunctionalTest extends FunctionalTestCase
$this->assertObjectNotHasAttribute('writeConcern', $event['started']->getCommand()); $this->assertObjectNotHasAttribute('writeConcern', $event['started']->getCommand());
} }
); );
$outCollection = new Collection($this->manager, $this->getDatabaseName(), $this->getCollectionName() . '.output');
$outCollection->drop();
} }
public function testEmptyPipelineReturnsAllDocuments() public function testEmptyPipelineReturnsAllDocuments()
......
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