Generates 'aggregate' command.
@param string $collectionName collection name
@param array $pipelines list of pipeline operators.
@param array $options optional parameters.
@return array command document.
11733
public function aggregate($collectionName, $pipelines, $options = [])
    {
        foreach ($pipelines as $key => $pipeline) {
            if (isset($pipeline['$match'])) {
                $pipelines[$key]['$match'] = $this->buildCondition($pipeline['$match']);
            }
        }

        $document = array_merge(
            [
                'aggregate' => $collectionName,
                'pipeline' => $pipelines,
                'allowDiskUse' => false,
            ],
            $options
        );

        return $document;
    }
167747
public function generateReports(SuiteCollection $collection, array $reportNames)
    {
        $reportDoms = [];
        $reportConfigs = [];

        foreach ($reportNames as $reportName) {
            $reportConfigs[$reportName] = $this->generatorRegistry->getConfig($reportName);
        }

        foreach ($reportConfigs as $reportName => $reportConfig) {
            $generatorName = $reportConfig['generator'];
            $generator = $this->generatorRegistry->getService($generatorName);

            $reportDom = $generator->generate($collection, $reportConfig);

            if (!$reportDom instanceof Document) {
                throw new \RuntimeException(sprintf(
                    'Report generator "%s" should have return a PhpBench\Dom\Document class, got: "%s"',
                    $generatorName,
                    is_object($reportDom) ? get_class($reportDom) : gettype($reportDom)
                ));
            }

            $reportDom->schemaValidate(__DIR__ . '/schema/report.xsd');

            $reportDoms[] = $reportDom;
        }

        return $reportDoms;
    }
703638
public function listCollections(array $options = [])
    {
        $this->setOptions($options);
        $coll = new Collection($this->client, $this->database);
        $coll->setHeaders($this->getHeaders());
        $rs = $coll->getAll();
        $this->checkResponse($rs);
        $colls = array_get($rs, 'DocumentCollections');
        $list = [];
        if (!empty($colls)) {
            foreach ($colls as $coll) {
                $list[] = array_get($coll, 'id');
            }
        }

        return $list;
    }
386006
protected function doCreateCollection($name, array $options)
    {
        $this->mongoDB->createCollection($name, $options);

        return $this->doSelectCollection($name);
    }
42575
public function getCollection(array $options = array())
    {
        /** @var UserEntity[] $collection */
        $collection = $this->userManager->findUsers();
        $resource   = new Resource($this->generateBrowseUrl(), array('count' => count($collection)));

        foreach ($collection as $element) {
            $resource->setEmbedded('user', $this->createResourceFromUser($element));
        }

        return $resource;
    }
126944
public function createDriver($options = [])
    {
        $options = $this->optionsResolver->resolve($options);

        return new CollectionDriver($this->extensions, $options['collection'], $options['criteria']);
    }
254436
protected function doAggregate(array $pipeline, array $options = array())
    {
        if (isset($options['cursor']) && ($options['cursor'] || is_array($options['cursor']))) {
            return $this->doAggregateCursor($pipeline, $options);
        }

        unset($options['cursor']);

        list($commandOptions, $clientOptions) = isset($options['socketTimeoutMS']) || isset($options['timeout'])
            ? $this->splitCommandAndClientOptions($options)
            : array($options, array());

        $command = array();
        $command['aggregate'] = $this->riakCollection->getName();
        $command['pipeline'] = $pipeline;
        $command = array_merge($command, $commandOptions);

        $database = $this->database;
        $result = $this->retry(function() use ($database, $command, $clientOptions) {
            return $database->command($command, $clientOptions);
        });

        if (empty($result['ok'])) {
            throw new ResultException($result);
        }

        /* If the pipeline ends with an $out operator, return a cursor on that
         * collection so a table scan may be performed.
         */
        if (isset($pipeline[count($pipeline) - 1]['$out'])) {
            $outputCollection = $pipeline[count($pipeline) - 1]['$out'];

            return $database->selectCollection($outputCollection)->find();
        }

        $arrayIterator = new ArrayIterator(isset($result['result']) ? $result['result'] : array());
        $arrayIterator->setCommandResult($result);

        return $arrayIterator;
    }
429993
public function setCollectionOptions(array $collectionOptions)
    {
        if ($this->nested) {
            throw new LogicException(
                sprintf(
                    'Collection options cannot be set for nested document class "%s".',
                    $this->documentClass
                )
            );
        }

        $this->collectionOptions = $collectionOptions;

        return $this;
    }
882814
public static function find($commandName, CommandCollection $commands)
    {
        $threshold = 1e3;
        $distancesByName = array();

        // Include aliases in the search
        $actualNames = $commands->getNames(true);

        foreach ($actualNames as $actualName) {
            // Get Levenshtein distance between the input and each command name
            $distance = levenshtein($commandName, $actualName);

            $isSimilar = $distance <= (strlen($commandName) / 3);
            $isSubString = false !== strpos($actualName, $commandName);

            if ($isSimilar || $isSubString) {
                $distancesByName[$actualName] = $distance;
            }
        }

        // Only keep results with a distance below the threshold
        $distancesByName = array_filter($distancesByName, function ($distance) use ($threshold) {
            return $distance < 2 * $threshold;
        });

        // Display results with shortest distance first
        asort($distancesByName);

        $suggestedNames = array_keys($distancesByName);

        return self::filterDuplicates($suggestedNames, $commands);
    }
102656
public function mongoDbAggregate($pipeline = [], $options = [], $useMaster = false)
    {
        $cmd = $options + [
                'aggregate' => $this->getRealTableName(key($this->table)),
                'pipeline' => $pipeline
            ];

        $data = $this->runMongoCommand($cmd, $useMaster);
        return $data[0]['result'];
    }
926098
public function collection($name, $options = null)
    {
        if (!isset($this->_collections[$name])) {
            $this->_collections[$name] = new Collection($name, $this->_connector, $options);
        }

        return $this->_collections[$name];
    }
90619
public function createCollection($name, array $options = null)
    {
        $classDefinition = $this->getCollectionDefinition($name);
        
        if (!empty($options)) {
            $classDefinition->merge($options);
        }

        $mongoCollection = $this->getMongoDB()->createCollection(
            $name,
            $classDefinition->getMongoCollectionOptions()
        );

        // create collection
        $className = $classDefinition->getClass();
        return new $className(
            $this,
            $mongoCollection,
            $classDefinition
        );
    }
723472
protected function doCreateCollection($name, array $options)
    {
        if (version_compare(phpversion('mongo'), '1.4.0', '>=')) {
            $this->riak->createCollection($name, $options);
        } else {
            $this->riak->createCollection($name, $options['capped'], $options['size'], $options['max']);
        }

        return $this->doSelectCollection($name);
    }
517420
def build_pipeline(self, collection):
        
        pipeline = []

        if isinstance(collection.where_dict, dict) and collection.where_dict:
            match_dict = {
                "$match": collection.where_dict
            }
            pipeline.append(match_dict)

        group_keys_dict = self.build_mongo_doc(self.join_keys)
        push_dict = self.build_mongo_doc(collection.select_keys)

        group_by_dict = {
            "$group":
                {
                    "_id": group_keys_dict,
                    "docs": {
                        "$push": push_dict
                    }
                }
        }

        pipeline.append(group_by_dict)

        return pipeline
98773
private function getCollectionOptionsHash(array $options)
    {
        ksort($options);
        $str = '';
        foreach ($options as $option) {
            if (!$option instanceof  Serializable) {
                // All valid Collection options are BSON serializable
                continue;
            }
            $str .= serialize($option->bsonSerialize());
        }

        return md5($str);
    }
798209
protected function generateTree(Collection $collection, Collection $children)
    {
        $children->map(function (AdminMenuInterface $menuItem) use ($collection, &$tree) {
            $tree[] = [
                'routeName' => $menuItem->getRouteName(),
                'cssClass'  => $menuItem->getCssClass(),
                'name'      => $menuItem->getName(),
                'children'  => $this->generateTree($collection, $this->filterElements($collection, $menuItem))
            ];
        });
        
        return $tree;
    }
385609
public function setCollectionName(string $collectionName)
    {
        if ($this->nested) {
            throw new LogicException(
                sprintf(
                    'Collection name cannot be set for nested document class "%s".',
                    $this->documentClass
                )
            );
        }

        $this->collectionName = $collectionName;

        return $this;
    }