ODM, ORM for php with MongoDB and how to connect

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

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

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top