MongoCursor::count PHP Method

count() public method

Counts the number of results for this query
public count ( boolean $foundOnly = false ) : integer
$foundOnly boolean Send cursor limit and skip information to the count function, if applicable.
return integer The number of documents returned by this cursor's query.
    public function count($foundOnly = false)
    {
        $optionNames = ['hint', 'maxTimeMS'];
        if ($foundOnly) {
            $optionNames = array_merge($optionNames, ['limit', 'skip']);
        }
        $options = $this->getOptions($optionNames) + $this->options;
        try {
            $count = $this->collection->count(TypeConverter::fromLegacy($this->query), $options);
        } catch (\MongoDB\Driver\Exception\ExecutionTimeoutException $e) {
            throw new MongoCursorTimeoutException($e->getMessage(), $e->getCode(), $e);
        } catch (\MongoDB\Driver\Exception\Exception $e) {
            throw ExceptionConverter::toLegacy($e);
        }
        return $count;
    }

Usage Example

コード例 #1
0
ファイル: modelCursor.php プロジェクト: mpcmf/mpcmf-core
 public function count($force = false)
 {
     if ($force || !isset($this->count)) {
         $this->count = $this->cursor->count();
     }
     return $this->count;
 }
All Usage Examples Of MongoCursor::count