@@ -116,10 +116,13 @@ class Aggregate implements Executable
116
116
* This is not supported for server versions < 3.4 and will result in an
117
117
* exception at execution time if used.
118
118
*
119
- * @param string $databaseName Database name
120
- * @param string $collectionName Collection name
121
- * @param array $pipeline List of pipeline operations
122
- * @param array $options Command options
119
+ * Note: Collection-agnostic commands (e.g. $currentOp) may be executed by
120
+ * specifying null for the collection name.
121
+ *
122
+ * @param string $databaseName Database name
123
+ * @param string|null $collectionName Collection name
124
+ * @param array $pipeline List of pipeline operations
125
+ * @param array $options Command options
123
126
* @throws InvalidArgumentException for parameter/option parsing errors
124
127
*/
125
128
public function __construct ($ databaseName , $ collectionName , array $ pipeline , array $ options = [])
@@ -220,7 +223,7 @@ public function __construct($databaseName, $collectionName, array $pipeline, arr
220
223
}
221
224
222
225
$ this ->databaseName = (string ) $ databaseName ;
223
- $ this ->collectionName = ( string ) $ collectionName ;
226
+ $ this ->collectionName = isset ( $ collectionName ) ? ( string ) $ collectionName : null ;
224
227
$ this ->pipeline = $ pipeline ;
225
228
$ this ->options = $ options ;
226
229
}
@@ -289,7 +292,7 @@ public function execute(Server $server)
289
292
private function createCommand (Server $ server )
290
293
{
291
294
$ cmd = [
292
- 'aggregate ' => $ this ->collectionName ,
295
+ 'aggregate ' => isset ( $ this ->collectionName ) ? $ this -> collectionName : 1 ,
293
296
'pipeline ' => $ this ->pipeline ,
294
297
];
295
298
$ cmdOptions = [];
0 commit comments