Xatoo Xatoo - 1 year ago 170
PHP Question

How to get cursor result count using the MongoDB PHP extension


PHP extension is deprecated in favour of the
extension. This extension is used together with the

In the old extension one could get the result count from the cursor using MongoCursor::count(). However, the new cursor MongoDB\Driver\Cursor has no such method. What is the new way of getting the number of results from after performing a query against MongoDB?

Answer Source

You can do it like this


The $whereClause would be your search criteria basically.

Otherwise, if your query returns an array, you could do

$data = Model::find(array($whereClause));
$total = count($data);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download