Class 'MongoDB\Client' not found, mongodb extension installed

same happened with me, check the version of php install on your server. You have to use php version 5.6 .Check the apche error log to get more precise error detail.


If you are using latest MongoDB extension of PHP, MongoDB\Driver\Manager is the main entry point to the extension.

Here is the sample code to retrieve data using latest extension.

Let's say you have testColl collection in testDb. The you can retrieve data using MongoDB\Driver\Query class of the extension.

// Manager Class
$manager = new MongoDB\Driver\Manager("mongodb://localhost:27017");

// Query Class
$query = new MongoDB\Driver\Query(array('age' => 30));

// Output of the executeQuery will be object of MongoDB\Driver\Cursor class
$cursor = $manager->executeQuery('testDb.testColl', $query);

// Convert cursor to Array and print result
print_r($cursor->toArray());

Output:

Array
(
    [0] => stdClass Object
        (
            [_id] => MongoDB\BSON\ObjectID Object
                (
                    [oid] => 5848f1394cea9483b430d5d2
                )

            [name] => XXXX
            [age] => 30
        )

)

I'm using PHP 7.1.9 and I had this issue. Solved it by removing and reinstalling mongodb/mongodb

composer remove mongodb/mongodb
composer require mongodb/mongodb

Also, If you are using Dreamweaver, don't for get to put the vendor folder in the server copy.

After installing, I can now use MongoDB\Client.

mongodb API Version 1.3, Mongodb Extension 1.4