MongoCursor::count

(PECL mongo >=0.9.2)

MongoCursor::countCounts the number of results for this query

说明

public MongoCursor::count ([ bool $foundOnly = FALSE ] ) : int

This method does not affect the state of the cursor: if you haven't queried yet, you can still apply limits, skips, etc. If you have started iterating through results, it will not move the current position of the cursor. If you have exhausted the cursor, it will not reset it.

参数

foundOnly

Send cursor limit and skip information to the count function, if applicable.

返回值

The number of documents returned by this cursor's query.

范例

Example #1 MongoCursor::count() example

<?php

$collection
->insert(array('x'=>1));
$collection->insert(array('x'=>2));
$collection->insert(array('x'=>3));

$cursor $collection->find();

var_dump($cursor->count());
var_dump($cursor->count(true));

$cursor->limit(2);

var_dump($cursor->count());
var_dump($cursor->count(true));

?>

以上例程的输出类似于:

int(3)
int(3)
int(3)
int(2)

错误/异常

Throws MongoConnectionException if it cannot reach the database.

相关文章
php informix 函数 returns the number of columns in the queryphp ingres 函数 get the number of fields returned by the last queryphp ingres 函数 get the number of rows affected or returned by a queryphp mongocursor counts the number of results for this queryphp mongocursor checks if there are results that have not yet been sent from the databasephp mongocursor execute the queryphp mongocursor return an explanation of the query often useful for optimization and debuggingphp mongocursor limits the number of results returnedphp mongocursor if this query should fetch partial results from mongos if a shard is downphp mongocursor set the read preference for this queryphp mongocursor skips a number of resultsphp mysqlnduhconnection returns the number of warnings from the last query for the given linkphp solrquery returns the maximum number of constraint counts that should be returned for the facet fieldsphp solrquery returns the maximum number of query terms that will be included in any generated queryphp solrquery specifies the number of results to return for each group. the server default value is 1php solrquery if true solr includes the number of groups that have matched the query in the resultsphp solrquery if true facet counts are based on the most relevant document of each group matching the queryphp spldoublylinkedlist counts the number of elements in the doubly linked listphp splpriorityqueue counts the number of elements in the queuephp ziparchive counts the number of files in the achive
关注编程学问公众号