Phalcon\Db\Adapter\MongoDB\Operation\Aggregate::__construct PHP Метод

__construct() публичный Метод

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. The default is false. * batchSize (integer): The number of documents to return per batch. * bypassDocumentValidation (boolean): If true, allows the write to opt out of document level validation. This only applies when the $out stage is specified. For servers < 3.2, this option is ignored as document level validation is not available. * maxTimeMS (integer): The maximum amount of time to allow the query to run. * readConcern (MongoDB\Driver\ReadConcern): Read concern. Note that a "majority" read concern is not compatible with the $out stage. For servers < 3.2, this option is ignored as read concern is not available. * readPreference (MongoDB\Driver\ReadPreference): Read preference. * typeMap (array): Type map for BSON deserialization. This will be applied to the returned Cursor (it is not sent to the server). This is not supported for inline aggregation results (i.e. useCursor option is false or the server versions < 2.6). * useCursor (boolean): Indicates whether the command will request that the server provide results using a cursor. The default is true. For servers < 2.6, this option is ignored as aggregation cursors are not available. For servers >= 2.6, this option allows users to turn off cursors if necessary to aid in mongod/mongos upgrades.
public __construct ( string $databaseName, string $collectionName, array $pipeline, array $options = [] )
$databaseName string Database name
$collectionName string Collection name
$pipeline array List of pipeline operations
$options array Command options
    public function __construct($databaseName, $collectionName, array $pipeline, array $options = [])
    {
        if (empty($pipeline)) {
            throw new InvalidArgumentException('$pipeline is empty');
        }
        $expectedIndex = 0;
        foreach ($pipeline as $i => $operation) {
            if ($i !== $expectedIndex) {
                throw new InvalidArgumentException(sprintf('$pipeline is not a list (unexpected index: "%s")', $i));
            }
            if (!is_array($operation) && !is_object($operation)) {
                throw InvalidArgumentException::invalidType(sprintf('$pipeline[%d]', $i), $operation, 'array or object');
            }
            $expectedIndex += 1;
        }
        $options += ['allowDiskUse' => false, 'useCursor' => true];
        if (!is_bool($options['allowDiskUse'])) {
            throw InvalidArgumentException::invalidType('"allowDiskUse" option', $options['allowDiskUse'], 'boolean');
        }
        if (isset($options['batchSize']) && !is_integer($options['batchSize'])) {
            throw InvalidArgumentException::invalidType('"batchSize" option', $options['batchSize'], 'integer');
        }
        if (isset($options['bypassDocumentValidation']) && !is_bool($options['bypassDocumentValidation'])) {
            throw InvalidArgumentException::invalidType('"bypassDocumentValidation" option', $options['bypassDocumentValidation'], 'boolean');
        }
        if (isset($options['maxTimeMS']) && !is_integer($options['maxTimeMS'])) {
            throw InvalidArgumentException::invalidType('"maxTimeMS" option', $options['maxTimeMS'], 'integer');
        }
        if (isset($options['readConcern']) && !$options['readConcern'] instanceof ReadConcern) {
            throw InvalidArgumentException::invalidType('"readConcern" option', $options['readConcern'], 'MongoDB\\Driver\\ReadConcern');
        }
        if (isset($options['readPreference']) && !$options['readPreference'] instanceof ReadPreference) {
            throw InvalidArgumentException::invalidType('"readPreference" option', $options['readPreference'], 'MongoDB\\Driver\\ReadPreference');
        }
        if (isset($options['typeMap']) && !is_array($options['typeMap'])) {
            throw InvalidArgumentException::invalidType('"typeMap" option', $options['typeMap'], 'array');
        }
        if (!is_bool($options['useCursor'])) {
            throw InvalidArgumentException::invalidType('"useCursor" option', $options['useCursor'], 'boolean');
        }
        if (isset($options['batchSize']) && !$options['useCursor']) {
            throw new InvalidArgumentException('"batchSize" option should not be used if "useCursor" is false');
        }
        if (isset($options['typeMap']) && !$options['useCursor']) {
            throw new InvalidArgumentException('"typeMap" option should not be used if "useCursor" is false');
        }
        $this->databaseName = (string) $databaseName;
        $this->collectionName = (string) $collectionName;
        $this->pipeline = $pipeline;
        $this->options = $options;
    }