Deprecated: Optional parameter $keys declared before required parameter $cms_id is implicitly treated as a required parameter in /home/www/dev/work/class/blog/CmsKey.php on line 75

Deprecated: Creation of dynamic property lvesu\lvesu\controller\blog\php::$title is deprecated in /home/www/dev/work/website/lvesu/class/controller/blog/php.php on line 28

Deprecated: Creation of dynamic property lvesu\lvesu\controller\blog\php::$outlink is deprecated in /home/www/dev/work/website/lvesu/template/blog/cms/php.manual.tpl on line 2

Deprecated: Creation of dynamic property lvesu\lvesu\controller\blog\php::$status is deprecated in /home/www/dev/work/website/lvesu/template/blog/index.head.php on line 2
PHP - Manual: MongoCursor::count - 互联网笔记

略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: MongoCursor::count

2025-07-01

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.

add a note add a note

User Contributed Notes

There are no user contributed notes for this page.

官方地址:https://www.php.net/manual/en/mongocursor.count.php

冷却塔厂家 广告
中文GPT4.0无需注册 广告
北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3