I'm using the MongoDB\Driver\Manager
to connect to MongoDB using PHP. The driver version is 1.6.14 and I can connect and make a query.
But I need the total number of documents for my query to make the pagination:
$reg_pag = 20;
$pag = $_GET["pag"];
$mng = new MongoDB\Driver\Manager("mongodb://localhost:27017");
$filter = [];
$filter["brand"] = $_GET["brand"];
$options = ["skip" => ($pag-1)*$reg_pag , "limit" => $reg_pag];
$query = new MongoDB\Driver\Query($filter, $options);
$rows = $mng->executeQuery("carsdb.cars", $query);
I try with $rows->count()
and with count($rows)
. The first command doesn't work and the last command returns the filtered data (return 20).