Get the number of documents in a collection

This will throw if the collection cannot be fetched from the server

@throws Exception

@param mixed $collection - collection id as a string or number

@return int - the number of documents in the collection
502419
public function count($collection)
    {
        $collection = $this->makeCollection($collection);
        $url        = UrlHelper::buildUrl(Urls::URL_COLLECTION, [$collection, self::OPTION_COUNT]);
        $response   = $this->getConnection()->get($url);

        $data  = $response->getJson();
        $count = $data[self::OPTION_COUNT];

        return (int) $count;
    }
190004
public function getAllIds($collection)
    {
        $params   = [
            self::OPTION_COLLECTION => $this->makeCollection($collection)
        ];
        $response = $this->getConnection()->put(Urls::URL_ALL_KEYS, $this->json_encode_wrapper($params));

        $data = $response->getJson();
        if (!isset($data[Cursor::ENTRY_RESULT])) {
            throw new ClientException('Got an invalid document list from the server');
        }

        $cursor = new Cursor($this->getConnection(), $response->getJson(), ['_documentClass' => $this->_documentClass]);
        $ids    = [];
        foreach ($cursor->getAll() as $location) {
            $ids[] = UrlHelper::getDocumentIdFromLocation($location);
        }

        return $ids;
    }
425475
protected function select($collection)
    {
        $em      = $this->getEntityManager($collection);
        $builder = $em->createQueryBuilder();

        $builder->select('count(e)')->from($collection, 'e');

        return $builder;
    }
565590
public function get($collection)
    {
        $collection = $this->makeCollection($collection);

        $url      = UrlHelper::buildUrl(Urls::URL_COLLECTION, [$collection]);
        $response = $this->getConnection()->get($url);

        $data = $response->getJson();

        return Collection::createFromArray($data);
    }
613280
public function size($collection=null) {
    list($collection) = self::_wrapArgs(func_get_args(), 1);
    
    $collection = self::_collection($collection);
    
    return self::_wrap(count((array) $collection));
  }
1327516
public function find($id)
    {
        $response = $this->client->request('GET', sprintf('/%s/%s', $this->name, $id));
        $json = (string) $response->getBody();

        if (404 === $response->getStatusCode()) {
            throw new Exception('Document does not exist');
        }

        return JSONEncoder::decode($json);
    }
1373148
public function transform($collection)
    {
        if (null === $collection) {
            return null;
        }

        if (!($collection instanceof Collection)) {
            throw new UnexpectedTypeException($collection, 'Doctrine\Common\Collection\Collection');
        }

        $results = array();
        foreach ($collection as $entity) {
            $results[] = $this->accessor->getValue($entity, $this->identifier);
        }

        //Here, do not put the result in the cache because we must check the value in
        //reverseTransform (by QueryBuilder)

        return $results;
    }
354611
public function count()
    {
        if ($this->count === null) {
            if ($this->dataSource instanceof \Countable) {
                $this->count = $this->dataSource->count();
            } elseif (is_array($this->dataSource)) {
                $this->count = count($this->dataSource);
            } else {
                throw new Exception\RuntimeException(sprintf(
                    'DataSource with type "%s" cannot be counted',
                    gettype($this->dataSource)
                ));
            }
        }
        return $this->count;
    }
284475
function count()
    {
        try {
            $count = $this->collection->count(
                [
                    'realm' => $this->getRealm(),
                ]
            );
        } catch (\Exception $e) {
            throw new exReadError($e->getMessage(), $e->getCode(), $e);
        }

        return $count;
    }
453000
public function count(): int
    {
        // If the count is already set, return it
        if(!is_null($this->count)) {
            return $this->count;
        }

        // Maually create a count by looping through the entities. This will
        // trigger the pagination calls to get the correct count of entities
        $count = 0;
        foreach($this as $entity) {
            $count++;
        }

        $this->count = $count;
        return $count;
    }
109250
public function count($filter = null)
    {
        if (is_null($filter)) {
            return $this->_countObjectsInCollection();
        } else if (is_string($filter)) {
            json_decode($filter);
            $isJson = (json_last_error() === JSON_ERROR_NONE) ? true :false;
            if ($isJson) {
                $filter = new Filter($filter);
                return $this->_countObjectsInCollectionByFilter($filter);
            }
        } else if (is_object($filter) && $filter instanceof Filter) {
            return $this->_countObjectsInCollectionByFilter($filter);
        }
        return 0;
    }
715471
protected function getListCollectionItem()
    {
        $id = $this->getParam(0);

        if (!isset($id)) {
            return $this->collection_item->getList(array('limit' => $this->getLimit()));
        }

        if (!is_numeric($id)) {
            $this->errorAndExit($this->text('Invalid argument'));
        }

        if ($this->getParam('collection')) {
            return $this->collection_item->getList(array('collection_id' => $id, 'limit' => $this->getLimit()));
        }

        $result = $this->collection_item->get($id);

        if (empty($result)) {
            $this->errorAndExit($this->text('Unexpected result'));
        }

        return array($result);
    }
339400
public function count() {
		$num = count($this->elements);
		if ($this->inheritedCollection !== null) {
			$num += $this->inheritedCollection->count();
		}
		return $num;
	}
1140734
public function get($ext)
    {
        if (! $this->has($ext) && ! $this->has('*')) {
            throw new Exception('There is no collection that collects for the extension ['.$ext.']');
        }

        if (! $this->has($ext) && $this->has('*')) {
            return $this->items[$this->lookupTable['*']];
        }

        return $this->items[$this->lookupTable[$ext]];
    }
691959
public function getCollectionId($collection)
    {
        if ($collection instanceof Collection) {
            $collectionId = $collection->getId();

            return $collectionId;
        }

        $collectionId = $collection;

        return $collectionId;
    }
303418
public function query($entity, $query)
	{
		$retValue = array();

		if (! is_null($this->_db)){
			try{
				$mongo = $this->_db->selectCollection($entity);

				// Find by query
				$cursor = $mongo->find($query);

				if (is_null($cursor))
					$retValue = array();
				else
					$retValue = iterator_to_array($cursor);
			}
			catch(Exception $e) {
				$this->_log->addError($e->getMessage());
			}	
		}

		return $retValue;
	}
688406
public function getBytes($count)
    {
        $count = (int) $count;

        if ($count < 0) {
            throw new \InvalidArgumentException('Number of bytes must be 0 or more');
        }

        return $this->generator->getBytes($count);
    }