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 函数 get number of rows affected by a queryphp maxdb 函数 returns the number of columns for the most recent queryphp maxdb 函数 check if there any more query results from a multi queryphp sqlsrv 函数 returns the number of rows modified by the last insert update or delete query executedphp mongocursor counts the number of results for this queryphp mongocursor gives the database a hint about the queryphp mongocursor limits the number of results returnedphp mongocursor if this query should fetch partial results from mongos if a shard is downphp mongocursor skips a number of resultsphp mongocursor sorts the results by given fieldsphp mongocursor sets whether this cursor will be left open after fetching the last resultsphp mongocursor sets a client side timeout for this queryphp mysqli returns the number of columns for the most recent queryphp sdo das relational 函数 executes an sql query passed as a prepared statement with a list of values to substitute for placeholders and return the results as a normalised data graphphp sdo das relational 函数 executes a given sql query against a relational database and returns the results as a normalised data graphphp solrquery allows grouping results based on the unique values of a function query group.func parameter php solrquery if true solr includes the number of groups that have matched the query in the resultsphp solrquery sets the maximum number of query terms includedphp splheap counts the number of elements in the heapphp weakmap counts the number of live entries in the map
关注编程学问公众号