MongoCursor::count

Counts the number of results for this query

&reftitle.description; public `int` `MongoCursor::count` `bool` `foundOnly`&false;

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 exhasted the cursor, it will not reset it.

&reftitle.parameters;

`foundOnly`

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

&reftitle.returnvalues;

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

&reftitle.examples;

### `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));

    ?>

&example.outputs.similar;

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

&reftitle.errors;

Throws `MongoConnectionException` if it cannot reach the database.