Haha, I’m in same boat.
After python PHP looking pretty terrible. 🙂
Silently returning null
instead of exceptions is a usual PHP behavior.
At first, you are using deprecated driver. See this explanation
So, working code will be looking like
<?php
echo "test mongodb connection\n";
$manager = new MongoDB\Driver\Manager('mongodb://localhost:27017');
$dbcol = new MongoDB\Collection($manager, 'db_name', 'collection_name');
$cursor = $dbcol->find();
foreach($cursor as $id => $value){
echo "ID: $id\n";
echo "Full data:\n";
print_r($value);
}
?>
CLICK HERE to find out more related problems solutions.