New in version 1.5.
- Specifies an aggregation pipeline operation.
An array specifying the desired options.NameTypeDescriptionallowDiskUsebooleanEnables writing to temporary files. When set to
true, aggregation stages can write data to the
_tmpsub-directory in the
Specifies the batch size for the cursor, which will apply to both the initial
aggregatecommand and any subsequent
getMorecommands. This determines the maximum number of documents to return in each response from the server.
A batchSize of
0is special in that and will only apply to the initial
getMorecommands will use the server's default batch size. This may be useful for quickly returning a cursor or failure from
aggregatewithout doing significant server-side work.bypassDocumentValidationbooleancollationarray|objectcommentmixedexplainbooleanSpecifies whether or not to return the information on the processing of the pipeline.hintstring|array|object
The index to use. Specify either the index name as a string or the index key pattern as a document. If specified, then the query system will only consider plans using the hinted index.letarray|object
Map of parameter names and values. Values must be constant or closed expressions that do not reference document fields. Parameters can then be accessed as variables in an aggregate expression context (e.g.
This is not supported for server versions prior to 5.0 and will result in an exception at execution time if used.
New in version 1.9.maxTimeMSinteger
The cumulative time limit in milliseconds for processing operations on the cursor. MongoDB aborts the operation at the earliest following interrupt point.readConcern
Read concern to use for the operation. Defaults to the database's read concern.readPreference
Read preference to use for the operation. Defaults to the database's read preference.session
Client session to associate with the operation.typeMaparray
The type map to apply to cursors, which determines how BSON documents are converted to PHP values. Defaults to the database's type map.writeConcern
Write concern to use for the operation. Defaults to the database's write concern.
MongoDB\\Exception\\UnexpectedValueException if the command
response from the server was malformed.
MongoDB\\Exception\\UnsupportedException if options are used and
not supported by the selected server (e.g.
MongoDB\\Exception\\InvalidArgumentException for errors related to
the parsing of parameters or options.
MongoDB\\Driver\\Exception\\RuntimeException for other errors at the driver level (e.g. connection errors).
The following aggregation example lists all running commands using the
$currentOp aggregation pipeline stage, then filters this list to only show
running command operations.
$database = (new MongoDB\Client)->admin; $cursor = $database->aggregate( [ ['$currentOp' => ], ['$match' => ['op' => 'command'], ] );