@@ -113,10 +113,12 @@ public function __construct($databaseName, $collectionName, array $pipeline, arr
113
113
*/
114
114
public function execute (Server $ server )
115
115
{
116
- $ command = $ this ->createCommand ($ server );
116
+ $ isCursorSupported = \MongoDB \server_supports_feature ($ server , self ::$ wireVersionForCursor );
117
+
118
+ $ command = $ this ->createCommand ($ server , $ isCursorSupported );
117
119
$ cursor = $ server ->executeCommand ($ this ->databaseName , $ command );
118
120
119
- if ($ this ->options ['useCursor ' ]) {
121
+ if ($ isCursorSupported && $ this ->options ['useCursor ' ]) {
120
122
return $ cursor ;
121
123
}
122
124
@@ -139,18 +141,19 @@ function (stdClass $document) { return (array) $document; },
139
141
/**
140
142
* Create the aggregate command.
141
143
*
142
- * @param Server $server
144
+ * @param Server $server
145
+ * @param boolean $isCursorSupported
143
146
* @return Command
144
147
*/
145
- private function createCommand (Server $ server )
148
+ private function createCommand (Server $ server, $ isCursorSupported )
146
149
{
147
150
$ cmd = array (
148
151
'aggregate ' => $ this ->collectionName ,
149
152
'pipeline ' => $ this ->pipeline ,
150
153
);
151
154
152
155
// Servers < 2.6 do not support any command options
153
- if ( ! \ MongoDB \server_supports_feature ( $ server , self :: $ wireVersionForCursor ) ) {
156
+ if ( ! $ isCursorSupported ) {
154
157
return new Command ($ cmd );
155
158
}
156
159
0 commit comments