Xatoo Xatoo - 8 months ago 98
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?


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