本文整理汇总了PHP中MongoCursor::count方法的典型用法代码示例。如果您正苦于以下问题:PHP MongoCursor::count方法的具体用法?PHP MongoCursor::count怎么用?PHP MongoCursor::count使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MongoCursor
的用法示例。
在下文中一共展示了MongoCursor::count方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: count
public function count($force = false)
{
if ($force || !isset($this->count)) {
$this->count = $this->cursor->count();
}
return $this->count;
}
示例2: count
/**
* Returns the total number of rows in the result set.
*
* @return int
*/
public function count()
{
if ($this->rowCount !== null) {
return $this->rowCount;
}
$this->rowCount = $this->cursor->count($foundOnly = true);
return $this->rowCount;
}
示例3: testDrop
public function testDrop()
{
$this->object->storeFile('tests/somefile');
$c = $this->object->chunks->count();
$this->assertGreaterThan(0, $c);
$this->assertEquals($this->count(), 1);
$this->object->drop();
$this->assertEquals($this->object->chunks->count(), 0);
$this->assertEquals($this->object->count(), 0);
}
示例4: totalCount
/**
* Count total number of items without limit and offset
* @return mixed
*/
public function totalCount()
{
if (!$this->count) {
$this->count = $this->cursor->count(false);
}
return $this->count;
}
示例5: getAffectedRows
/**
* Get affected rows
*
* @return int
*/
public function getAffectedRows()
{
if ($this->resource instanceof \MongoCursor) {
return $this->resource->count();
}
return $this->resource;
}
示例6: __construct
/**
* Construct by passing in the \MongoCursor and the object to populate
* @param \MongoCursor $cursor
*/
public function __construct(\MongoCursor $cursor, Collection $collection)
{
$this->cursor = $cursor;
$this->count = $cursor->count(true);
$this->position = 0;
$this->collection = $collection;
}
示例7: count
/**
* Count the results from the query
*
* + Count the results from the current query: pass false for "all" results (disregard limit/skip)
* + Count results of a separate query: pass an array or JSON string of query parameters
*
* @since 0.3.0
*
* See [\Countable::count]
*
* @link http://www.php.net/manual/en/mongocursor.count.php \MongoCursor::count
*
* @param boolean|array|string $query
*
* @return integer
*
* @throws \Exception
*
* @uses \JSON::encodeMongo
* @uses \JSON::decode
* @uses \Profiler::start
* @uses \Profiler::stop
*/
public function count($query = true)
{
if (is_bool($query)) {
// Profile count operation for cursor
if ($this->getClientInstance()->profiling) {
$this->benchmark = Profiler::start(get_class($this->getClientInstance()) . "::{$this->db}", $this->shellQuery() . ".count(" . JSON::encodeMongo($query) . ")");
}
$this->cursor || $this->load();
$count = $this->cursor->count($query);
} else {
if (is_string($query) && $query[0] == "{") {
$query = JSON::decode($query, true);
}
$query_trans = array();
foreach ($query as $field => $value) {
$query_trans[$this->getFieldName($field)] = $value;
}
$query = $query_trans;
// Profile count operation for collection
if ($this->getClientInstance()->profiling) {
$this->benchmark = Profiler::start(get_class($this->getClientInstance()) . "::{$this->db}", "db.{$this->name}.count(" . ($query ? JSON::encodeMongo($query) : '') . ")");
}
$count = $this->getCollection()->count($query);
}
// End profiling count
if ($this->benchmark) {
// Stop the benchmark
Profiler::stop($this->benchmark);
// Clean benchmark token
$this->benchmark = null;
}
return $count;
}
示例8: getPaginator
/**
* Performs proper skip and limit to get
* data package that can be wraped in paginator
*
* @param int $perPage
* @param int $page
* @param mixed $options Options you want to pass
*/
public function getPaginator($perPage = 10, $page = 1, $options = null)
{
$this->_checkCursor();
$total = $this->_cursor->count();
$this->_cursor->skip(($page - 1) * $perPage)->limit($perPage);
$result = $this->get();
return $this->_createPaginator($result, $total, $perPage, $page, $options);
}
示例9: calculateTotalItemCount
/**
* @see CActiveDataProvider::calculateTotalItemCount()
* @return int
*/
public function calculateTotalItemCount()
{
if (!$this->_cursor) {
$criteria = $this->getCriteria();
$this->_cursor = $this->model->find(isset($criteria['condition']) && is_array($criteria['condition']) ? $criteria['condition'] : array());
}
return $this->_cursor->count();
}
示例10: calculateTotalItemCount
/**
* @see CActiveDataProvider::calculateTotalItemCount()
* @return int
*/
public function calculateTotalItemCount()
{
if (!$this->_builder) {
$criteria = $this->getCriteria();
$this->_builder = new EMongoQueryBuilder($this->model, isset($criteria['condition']) && is_array($criteria['condition']) ? $criteria['condition'] : []);
}
return $this->_builder->count();
}
示例11: count
/**
* Count the results
*
* @since v1.0.0
*/
public function count($foundOnly = FALSE)
{
$count = array();
try {
$count = $this->_cursor->count($foundOnly);
} catch (MongoCursorException $exception) {
show_error($exception->getMessage(), 500);
} catch (MongoConnectionException $exception) {
show_error($exception->getMessage(), 500);
} catch (MongoCursorTimeoutException $exception) {
show_error($exception->getMessage(), 500);
}
return $count;
}
示例12: count
/**
* count method on the cursor, allows to get result count
*
* @param bool $foundOnly
* @return int
*/
public function count($foundOnly = false)
{
return $this->myResultCursor->count($foundOnly);
}
示例13: count
/**
* Returns the number of documents found
* {@see http://www.php.net/manual/en/mongocursor.count.php}
* @param boolean $foundOnly default TRUE
* @return integer count of documents found
* @since v1.3.4
*/
public function count($foundOnly = true)
{
return $this->_cursor->count($foundOnly);
}
示例14: __construct
/**
* Constructor.
*
* @param \Iterator $iterator Iterator to paginate
* @throws \Zend\Paginator\Adapter\Exception\InvalidArgumentException
*/
public function __construct(\MongoCursor $iterator)
{
$this->iterator = $iterator;
$this->count = $iterator->count();
}
示例15: createResult
/**
* @param \MongoCursor $resource
* @param mixed $context
* @return Result
*/
public function createResult($resource, $context = null)
{
$result = clone $this->resultPrototype;
if ($resource instanceof \MongoCursor) {
$rowCount = $resource->count($foundOnly = true);
} elseif (is_array($resource) && isset($resource['n'])) {
$rowCount = (int) $resource['n'];
// $resource = $this -> connection -> getDB() -> selectCollection( $context ) -> find( ['_id' => $this -> connection -> getLastGeneratedValue( $context ) ] );
} else {
$rowCount = (int) $resource;
// $resource = $this -> connection -> getDB() -> selectCollection( $context ) -> find( ['_id' => $this -> connection -> getLastGeneratedValue( $context ) ] );
}
$result->initialize($resource, $this->connection->getLastGeneratedValue($context), $rowCount);
return $result;
}