I'm using mongodb driver to connect to mongodb through PHP. I was unable to connect to mongodb using mongoClient().
Versions of my php and mongodb
php --version output
mongo --version output

so, I tried to connect it through mongodb driver. Here's the code...
$connection = new MongoDB\Driver\Manager("mongodb://localhost:27017");
$bulk = new MongoDB\Driver\BulkWrite;
$bulk->insert(["number"=>$Number, "created"=>time()]);
$connection-> executeBulkWrite("dbName.collectionName", $bulk);
This is working fine to insert the data to mongodb.
Now, I want to get the no. of rows from a collection in database but unable to find any solution.
I tried this code for retrieving data from mongodb:
try {
$connection = new MongoDB\Driver\Manager("mongodb://localhost:27017");
$filter = ["number"=> $Number];
$query_mongo = new MongoDB\Driver\Query($filter);
$mongoResult = $connection->executeQuery("dbName.collectionName", $query_mongo);
$result = current($mongoResult->toArray());
var_dump($result);
} catch (MongoDB\Driver\Exception\Exception $e) {
$filename = basename(__FILE__);
echo "The $filename script has experienced an error.\n";
echo "It failed with the following exception:\n";
echo "Exception:", $e->getMessage(), "\n";
echo "In file:", $e->getFile(), "\n";
echo "On line:", $e->getLine(), "\n";
}
But I'm getting this error in browser console...
parsererror,SyntaxError: Unexpected token o in JSON at position 0,object(stdClass)#26 (3) {
["_id"]=>
object(MongoDB\BSON\ObjectID)#25 (1) {
["oid"]=>
string(24) "587c6e37e2d11616411c90a2"
}
["number"]=>
string(10) "123456"
["created"]=>
int(1484549687)
}
Q1. can I get rid of this Mongodb\Driver\Manager and use the old mongoClient and How?
Q2. I want to get no. of rows in the table. How can i do that using this Driver\Manager?
Q3. Any solution to the given error?
Thanks in advance...