MongoCollection
在线手册:中文 英文
PHP手册

MongoCollection::count

(PECL mongo >=0.9.0)

MongoCollection::countCounts the number of documents in this collection

说明

public int MongoCollection::count ([ array $query = array() [, int $limit = 0 [, int $skip = 0 ]]] )

参数

query

Associative array or object with fields to match.

limit

Specifies an upper limit to the number returned.

skip

Specifies a number of results to skip before starting the count.

返回值

Returns the number of documents matching the query.

更新日志

版本 说明
1.0.7 Added limit and skip parameters.

范例

Example #1 MongoCollection::count() example

<?php

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

var_dump($collection->count());
var_dump($collection->count(array('x'=>1)));

?>

以上例程的输出类似于:

int(3)
int(1)

MongoCollection
在线手册:中文 英文
PHP手册