Skip to content

Commit d26149b

Browse files
committed
Aggregate should check server support before returning a cursor
1 parent 6bdecdb commit d26149b

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/Operation/Aggregate.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,12 @@ public function __construct($databaseName, $collectionName, array $pipeline, arr
113113
*/
114114
public function execute(Server $server)
115115
{
116-
$command = $this->createCommand($server);
116+
$isCursorSupported = \MongoDB\server_supports_feature($server, self::$wireVersionForCursor);
117+
118+
$command = $this->createCommand($server, $isCursorSupported);
117119
$cursor = $server->executeCommand($this->databaseName, $command);
118120

119-
if ($this->options['useCursor']) {
121+
if ($isCursorSupported && $this->options['useCursor']) {
120122
return $cursor;
121123
}
122124

@@ -139,18 +141,19 @@ function (stdClass $document) { return (array) $document; },
139141
/**
140142
* Create the aggregate command.
141143
*
142-
* @param Server $server
144+
* @param Server $server
145+
* @param boolean $isCursorSupported
143146
* @return Command
144147
*/
145-
private function createCommand(Server $server)
148+
private function createCommand(Server $server, $isCursorSupported)
146149
{
147150
$cmd = array(
148151
'aggregate' => $this->collectionName,
149152
'pipeline' => $this->pipeline,
150153
);
151154

152155
// Servers < 2.6 do not support any command options
153-
if ( ! \MongoDB\server_supports_feature($server, self::$wireVersionForCursor)) {
156+
if ( ! $isCursorSupported) {
154157
return new Command($cmd);
155158
}
156159

0 commit comments

Comments
 (0)