芝麻web文件管理V1.00
编辑当前文件:/home/mgatv524/lot.mgaplay.com.br/vendor/mongodb/mongodb/src/Operation/CountDocuments.php
databaseName = (string) $databaseName; $this->collectionName = (string) $collectionName; $this->filter = $filter; $this->aggregateOptions = array_intersect_key($options, ['collation' => 1, 'hint' => 1, 'maxTimeMS' => 1, 'readConcern' => 1, 'readPreference' => 1, 'session' => 1]); $this->countOptions = array_intersect_key($options, ['limit' => 1, 'skip' => 1]); $this->aggregate = $this->createAggregate(); } /** * Execute the operation. * * @see Executable::execute() * @param Server $server * @return integer * @throws UnexpectedValueException if the command response was malformed * @throws UnsupportedException if collation or read concern is used and unsupported * @throws DriverRuntimeException for other driver errors (e.g. connection errors) */ public function execute(Server $server) { $cursor = $this->aggregate->execute($server); $allResults = $cursor->toArray(); /* If there are no documents to count, the aggregation pipeline has no items to group, and * hence the result is an empty array (PHPLIB-376) */ if (count($allResults) == 0) { return 0; } $result = current($allResults); if (! isset($result->n) || ! (is_integer($result->n) || is_float($result->n))) { throw new UnexpectedValueException('count command did not return a numeric "n" value'); } return (integer) $result->n; } /** * @return Aggregate */ private function createAggregate() { $pipeline = [ ['$match' => (object) $this->filter], ]; if (isset($this->countOptions['skip'])) { $pipeline[] = ['$skip' => $this->countOptions['skip']]; } if (isset($this->countOptions['limit'])) { $pipeline[] = ['$limit' => $this->countOptions['limit']]; } $pipeline[] = ['$group' => ['_id' => 1, 'n' => ['$sum' => 1]]]; return new Aggregate($this->databaseName, $this->collectionName, $pipeline, $this->aggregateOptions); } }