PHPKonf 2020 Online

MongoCursor::count

(PECL mongo >=0.9.2)

MongoCursor::countCounts the number of results for this query

Açıklama

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.

Değiştirgeler

foundOnly

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

Dönen Değerler

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

Örnekler

Örnek 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));

?>

Yukarıdaki örnek şuna benzer bir çıktı üretir:

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

Hatalar/İstisnalar

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.
To Top