mongodb num_rows equivalent php

mongodb, php

Solution

Like this, I think:

$collection = $connection->myDB->myCollection;
$cursor = $collection->find(array("email" => $newemail, "password" => $newpass));
$nResults = $cursor->count();

Problem

how can i get the number of results, equivalent to `num_rows`(mysqli) in `mongodb`? if i have ``` $db->$dbName->find(array("email" => $newemail, "password" => $newpass)); ``` what is the best way to check the number of results that match this criteria? in mysqli i would do something like ``` $sql = "SELECT id FROM table WHERE email='%s' AND password='%s'"; $query = sprintf($sql, $newemail, $newpass); $result = $conn->query($query); $rows = $result->num_rows; ```

Original source