@@ -116,10 +116,13 @@ class Aggregate implements Executable
116116 * This is not supported for server versions < 3.4 and will result in an
117117 * exception at execution time if used.
118118 *
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
123126 * @throws InvalidArgumentException for parameter/option parsing errors
124127 */
125128 public function __construct ($ databaseName , $ collectionName , array $ pipeline , array $ options = [])
@@ -220,7 +223,7 @@ public function __construct($databaseName, $collectionName, array $pipeline, arr
220223 }
221224
222225 $ this ->databaseName = (string ) $ databaseName ;
223- $ this ->collectionName = ( string ) $ collectionName ;
226+ $ this ->collectionName = isset ( $ collectionName ) ? ( string ) $ collectionName : null ;
224227 $ this ->pipeline = $ pipeline ;
225228 $ this ->options = $ options ;
226229 }
@@ -289,7 +292,7 @@ public function execute(Server $server)
289292 private function createCommand (Server $ server )
290293 {
291294 $ cmd = [
292- 'aggregate ' => $ this ->collectionName ,
295+ 'aggregate ' => isset ( $ this ->collectionName ) ? $ this -> collectionName : 1 ,
293296 'pipeline ' => $ this ->pipeline ,
294297 ];
295298 $ cmdOptions = [];
0 commit comments