MongoCursor
PHP Manual

MongoCursor::count

(PECL mongo >=0.9.2)

MongoCursor::countCounts the number of results for this query

Opis

public int MongoCursor::count ([ boolean $all = FALSE ] )

Parametry

all

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

Zwracane wartości

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

Przykłady

Przykład #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));

?>

Powyższy przykład wyświetli coś podobnego do:

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

Błędy/Wyjątki

Throws MongoConnectionException if it cannot reach the database.


MongoCursor
PHP Manual