Skip to content

PHP MongoDB: Fatal error: Class ‘MongoClient’ not found


When executing following PHP code:

$m = new MongoClient("mongodb://localhost:27017");

I get following error:

Fatal error: Class ‘MongoClient’ not found in (…)

MongoDB extension seems properly installed (I copied php_mongodb.dll to ext folder and updated php.ini).

PHP seems to confirm that extension is running properly as the following code confirms it is loaded:

echo extension_loaded("mongodb") ? "loaded\n" : "not loaded\n";

Also, phpinfo() shows that mongodb extension has been loaded.


Problem still not solved.

phpinfo() clearly shows that the driver is loaded:

enter image description here


The class MongoClient is part of the legacy PECL package mongo but not anymore of the up-to-date mongodb package.

On MongoDB PHP driver github repo, the release note about the version 1.0.0, is suggesting developers to use MongoDB\Driver\Manager instead of MongoClient

Changes from our legacy mongo extension

Most significantly, the legacy driver’s MongoClient, MongoDB, and MongoCollection classes have been obsoleted by the MongoDB\Driver\Manager class, which is the new gateway for connecting and executing queries, commands, and write operations.

Posted in datatable. Tagged with , .