Werbung
MongoCursor::count
(PECL mongo >=0.9.2)
MongoCursor::count — Counts the number of results for this query
Beschreibung
public int MongoCursor::count
([ boolean $all = FALSE
] )
Parameter-Liste
- all
-
Send cursor limit and skip information to the count function, if applicable.
Rückgabewerte
The number of documents returned by this cursor's query.
Beispiele
PHP Code
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
$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));
Das oben gezeigte Beispiel erzeugt eine ähnliche Ausgabe wie:
int(3) int(3) int(3) int(2)
Fehler/Exceptions
Throws MongoConnectionException if it cannot reach the database.