Returns a count according to the $query and $groupBy conditions
@param array $query Mongo query object
@param null $groupBy
@param null $ttl acceptable time to live if you're willing to accept a cached version of this request
@return array|int
358230
public function getCount($query,$groupBy=null,$ttl=null)
    {
        $t = new \Tripod\Timer();
        $t->start();

        $id = null;
        $results = null;
        if (!empty($ttl))
        {
            $id['query'] = $query;
            $id['groupBy'] = $groupBy;
            $this->debugLog("Looking in cache",array("id"=>$id));
            $candidate = $this->config->getCollectionForTTLCache($this->storeName)->findOne(array(_ID_KEY => $id));
            if (!empty($candidate))
            {
                $this->debugLog("Found candidate",array("candidate"=>$candidate));

                $ttlTo = \Tripod\Mongo\DateUtil::getMongoDate((( (int) $candidate['created']->__toString() / 1000) + $ttl) * 1000);
                if ($ttlTo>(\Tripod\Mongo\DateUtil::getMongoDate()))
                {
                    // cache hit!
                    $this->debugLog("Cache hit",array("id"=>$id));
                    $results = $candidate['results'];
                }
                else
                {
                    // cache miss
                    $this->debugLog("Cache miss",array("id"=>$id));
                }
            }
        }
        if (empty($results))
        {
            if ($groupBy)
            {
                $ops = [
                    ['$match' => $query],
                    ['$group' => [_ID_KEY => '$'.$groupBy,'total' => ['$sum' => 1]]]
                ];
                $cursor = $this->collection->aggregate($ops);
                foreach($cursor as $doc) {
                    if (!is_array($doc[_ID_KEY])) {
                        $results[$doc[_ID_KEY]] = $doc['total'];
                    } else {
                        $results[implode(';',$doc[_ID_KEY])] = $doc['total'];
                    }
                }
            }
            else
            {
                $results = $this->collection->count($query);
            }

            if (!empty($ttl))
            {
                // add to cache
                $cachedResults = array();
                $cachedResults[_ID_KEY] = $id;
                $cachedResults['results'] = $results;
                $cachedResults['created'] = \Tripod\Mongo\DateUtil::getMongoDate();
                $this->debugLog("Adding result to cache",$cachedResults);
                $result = $this->config->getCollectionForTTLCache($this->storeName)->insertOne($cachedResults);
                if (!$result->isAcknowledged()) {
                    $this->debugLog("Insert cache result not acknowledged");
                }
            }
        }

        $t->stop();
        $op = ($groupBy) ? MONGO_GROUP : MONGO_COUNT;
        $this->timingLog($op, array('duration'=>$t->result(), 'query'=>$query));
        $this->getStat()->timer("$op.{$this->podName}",$t->result());

        return $results;
    }
861005
public function count($name, $query, CountableFilterInterface $filter)
    {
        // if the columnname is not set, assume an id field based on a table name
        $columnName  = (empty($this->columnName))
                            ?   $name
                            :   $this->columnName;

        if ( ! $this->includeEmpty) {
            $query->whereNotNull($columnName);
        }

        return $query->select(
                        "{$columnName} AS {$this->columnAlias}",
                        DB::raw("{$this->countRaw} AS {$this->countAlias}")
                     )
                     ->groupBy($columnName)
                     ->pluck($this->countAlias, $this->columnAlias);
    }
649148
public static function aggregate($query)
    {
        $rows = self::connection()->aggregate(self::collectionName(), $query);
        return $rows;
    }
517058
public function runSparql(string $query, int $nTries = null): Result {
        return $this->sparqlClient->query($query, $nTries ?? $this->sparqlNTries);
    }
1228247
private function query($query)
    {
		if(!is_array($query)) {
			return q($query);
		} else {
			foreach($query as $v) {
				q($v);
			}
			return true;
		}
    }
1288392
function paginateCount($conditions, $recursive){

		$sql  = $this->sql;
		return count($this->query($sql));
	}
164593
public function getRelationCountQuery(Builder $query, Builder $parent)
    {
        $query->select(new Expression('count(*)'));

        $otherKey = $this->wrap($query->getModel()->getTable().'.'.$this->otherKey);

        return $query->where($this->getQualifiedForeignKey(), '=', new Expression($otherKey));
    }
539562
public static function count($collection, $query = null)
  {
    static::checkConnexion();
    $collection = self::$db->$collection;
    if (is_string($query)) {
      $query = json_decode($query, true);
      if(!$query){
        throw new \Exception('Requête JSON formulée incorrectement');
      }
    }
    if ($query) {
      return $collection->count($query);
    } else {
      return $collection->count();
    }
  }
407070
public static function isIndexedArray(array $query)
    {
        if (empty($query) || !isset($query[0])) {
            return false;
        }

        return array_keys($query) === range(0, count($query) - 1);
    }
159955
public function getRelationCountQuery(Query $query, Query $parent)
    {
        $query->select(new Expression('count(*)'));

        $key = $this->wrap($this->getQualifiedParentKeyName());

        return $query->where($this->getHasCompareKey(), '=', new Expression($key));
    }
240792
function count($filter=NULL,array $options=NULL,$ttl=0) {
		if (!($subquery_mode=($options && !empty($options['group']))))
			$this->adhoc['_rows']=['expr'=>'COUNT(*)','value'=>NULL];
		$adhoc=[];
		foreach ($this->adhoc as $key=>$field)
			// Add all adhoc fields
			// (make them available for grouping, sorting, having)
			$adhoc[]=$field['expr'].' AS '.$this->db->quotekey($key);
		$fields=implode(',',$adhoc);
		if ($subquery_mode) {
			if (empty($fields))
				// Select at least one field, ideally the grouping fields
				// or sqlsrv fails
				$fields=preg_replace('/HAVING.+$/i','',$options['group']);
			if (preg_match('/mssql|dblib|sqlsrv/',$this->engine))
				$fields='TOP 100 PERCENT '.$fields;
		}
		list($sql,$args)=$this->stringify($fields,$filter,$options);
		if ($subquery_mode)
			$sql='SELECT COUNT(*) AS '.$this->db->quotekey('_rows').' '.
				'FROM ('.$sql.') AS '.$this->db->quotekey('_temp');
		$result=$this->db->exec($sql,$args,$ttl);
		unset($this->adhoc['_rows']);
		return (int)$result[0]['_rows'];
	}
1019508
def count(self, query):
        
        body = {
            "query": {
                "bool": {
                    "must": [{
                        "query_string": {
                            "query": query,
                        }
                    }]
                }
            }
        }

        body['query']['bool']['must'].append(self._get_timestamp_filer())

        return self._es.count(index=self._index, body=body).get('count')
513736
public function runCount($query)
	{
		if (isset($this->stored_query_totals[md5(serialize($query))])) {
			return $this->stored_query_totals[md5(serialize($query))];
		}
		
		try {
			return array_get($this->getClient()->search($query), 'hits.total');
		} catch (\Elasticsearch\Common\Exceptions\Missing404Exception $e) {
			return 0;
		}
	}
793274
private function buildAggQueryData($query)
    {
        $ret = [];

        foreach ($this->aggregations as $agg) {
            $additions = $agg->buildQueryData($this, $query);
            if ($additions) {
                $ret = array_merge($ret, $additions);
            }
        }

        return $ret;
    }
1166505
public static function executeNone(string $query): int
  {
    self::realQuery($query);

    $n = self::$mysqli->affected_rows;

    if (self::$mysqli->more_results()) self::$mysqli->next_result();

    return $n;
  }
1118323
public function count($collection = '', $foundonly = false)
	{
		if (empty($collection))
		{
			throw new \Mongo_DbException("In order to retrieve a count of documents from MongoDB you must provide a collection name.");
		}

		if ($this->profiling)
		{
			$query = json_encode(array(
			'type'			=> 'count',
			'collection'	=> $collection,
			'where'			=> $this->wheres,
			'limit'			=> $this->limit,
			'offset'		=> $this->offset,
			));

			$benchmark = \Profiler::start((string) $this->db, $query);
		}

		$count = $this->db->{$collection}->find($this->wheres)->limit((int) $this->limit)->skip((int) $this->offset)->count($foundonly);

		if (isset($benchmark))
		{
			\Profiler::stop($benchmark);
		}

		$this->_clear();
		return ($count);
	}
863057
public function countByQuery($query)
    {
        $queryCount = clone $query;
        $queryCount->setCols('count(*) as count');
        $result = $this->getDB()->execute($queryCount);

        if ($result->numRows()) {
            $row = $result->fetchResult();

            return (int)$row['count'];
        }

        return false;
    }