MongoCollection
PHP Manual

MongoCollection::count

(PECL mongo >=0.9.0)

MongoCollection::countCounts the number of documents in this collection

설명

public int MongoCollection::count ([ array $query= array() [, array $fields= array() ]] )

인수

query

Only count documents matching this query.

fields

Only count documents with these fields.

반환값

Returns the number of documents.

예제

Example #1 MongoCollection::count() example

<?php

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

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

?>

위 예제의 출력 예시:

float(3)
float(1)
float(0)

MongoCollection
PHP Manual