Aggregate
in package
implements
Executable, Explainable
Operation for the aggregate command.
Tags
Interfaces, Classes, Traits and Enums
- Executable
- Explainable
Table of Contents
- $collectionName : string|null
- $databaseName : string
- $isExplain : bool
- $isWrite : bool
- $options : array<string|int, mixed>
- $pipeline : array<string|int, mixed>
- __construct() : mixed
- Constructs an aggregate command.
- execute() : Traversable
- Execute the operation.
- getCommandDocument() : array<string|int, mixed>
- Returns the command document for this operation.
- createCommandDocument() : array<string|int, mixed>
- Create the aggregate command document.
- createCommandOptions() : array<string|int, mixed>
- executeCommand() : Cursor
- Execute the aggregate command using the appropriate Server method.
Properties
$collectionName
private
string|null
$collectionName
$databaseName
private
string
$databaseName
$isExplain
private
bool
$isExplain
$isWrite
private
bool
$isWrite
$options
private
array<string|int, mixed>
$options
$pipeline
private
array<string|int, mixed>
$pipeline
Methods
__construct()
Constructs an aggregate command.
public
__construct(string $databaseName, string|null $collectionName, array<string|int, mixed> $pipeline[, array<string|int, mixed> $options = [] ]) : mixed
Supported options:
-
allowDiskUse (boolean): Enables writing to temporary files. When set to true, aggregation stages can write data to the _tmp sub-directory in the dbPath directory.
-
batchSize (integer): The number of documents to return per batch.
-
bypassDocumentValidation (boolean): If true, allows the write to circumvent document level validation. This only applies when an $out or $merge stage is specified.
-
collation (document): Collation specification.
-
comment (string): An arbitrary string to help trace the operation through the database profiler, currentOp, and logs.
-
explain (boolean): Specifies whether or not to return the information on the processing of the pipeline.
-
hint (string|document): 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.
-
let (document): 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. "$$var").
This is not supported for server versions < 5.0 and will result in an exception at execution time if used.
-
maxTimeMS (integer): The maximum amount of time to allow the query to run.
-
readConcern (MongoDB\Driver\ReadConcern): Read concern.
-
readPreference (MongoDB\Driver\ReadPreference): Read preference.
This option is ignored if an $out or $merge stage is specified.
-
session (MongoDB\Driver\Session): Client session.
-
typeMap (array): Type map for BSON deserialization. This will be applied to the returned Cursor (it is not sent to the server).
-
useCursor (boolean): Indicates whether the command will request that the server provide results using a cursor. The default is true.
This option allows users to turn off cursors if necessary to aid in mongod/mongos upgrades.
-
writeConcern (MongoDB\Driver\WriteConcern): Write concern. This only applies when an $out or $merge stage is specified.
Note: Collection-agnostic commands (e.g. $currentOp) may be executed by specifying null for the collection name.
Parameters
- $databaseName : string
-
Database name
- $collectionName : string|null
-
Collection name
- $pipeline : array<string|int, mixed>
-
List of pipeline operations
- $options : array<string|int, mixed> = []
-
Command options
Tags
Return values
mixed —execute()
Execute the operation.
public
execute(Server $server) : Traversable
Parameters
- $server : Server
Tags
Return values
Traversable —getCommandDocument()
Returns the command document for this operation.
public
getCommandDocument(Server $server) : array<string|int, mixed>
Parameters
- $server : Server
Tags
Return values
array<string|int, mixed> —createCommandDocument()
Create the aggregate command document.
private
createCommandDocument() : array<string|int, mixed>
Return values
array<string|int, mixed> —createCommandOptions()
private
createCommandOptions() : array<string|int, mixed>
Return values
array<string|int, mixed> —executeCommand()
Execute the aggregate command using the appropriate Server method.
private
executeCommand(Server $server, Command $command) : Cursor
Parameters
- $server : Server
- $command : Command