Class mongodb client not found

I tried to create new mongo connection executing the following code

$m = new MongoDB\Client();

and i got this error:

Fatal error: Class 'MongoDB\Client' not found

i think i have properly installed MongoDB extension (Copied php_mongodb.dll to ext folder and updated php.ini with extension=php_mongodb.dll).

The following code confirms it is loaded:

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

I still receive the same error.

Here is phpinfo()

I appreciate all your help. Thank you!

Rusty

8,09610 gold badges53 silver badges73 bronze badges

asked Dec 5, 2016 at 10:02

Class mongodb client not found

6

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
        )

)

answered Dec 8, 2016 at 5:47

Class mongodb client not found

dikeshdikesh

2,7052 gold badges16 silver badges25 bronze badges

2

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

answered Feb 28, 2018 at 7:15

RustyRusty

8,09610 gold badges53 silver badges73 bronze badges

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.

answered Dec 5, 2016 at 10:09

4

Just simple way to install

sudo apt-get install php-mongodb

after install mongo

Class mongodb client not found

Elangovan

3,3794 gold badges30 silver badges37 bronze badges

answered Jul 3, 2018 at 9:56

Different for Apache and Nginx it appears.

Though this post is old but I help this migh help someone. I recently ran into same problem. With me it was s different php.ini.

I kept placing the mongoextension into /cli/php.ini.

Thoough when I ran I found out that in my case the loaded configuration is in /fpm/php.ini. This was because I was unsing Nginx with fpm.

answered Jul 25, 2020 at 3:30

Class mongodb client not found

90% of the time it is your Mongodb extension configuration. kindly check in php.ini

answered Jul 22, 2020 at 19:48

Class mongodb client not found

KiprutoKipruto

4514 silver badges13 bronze badges

\MongoDB\Driver\Manager(); is now "low level" extension (php_mongodb), \MongoDB\Client was rewritten to "PHP class" and you need extra install https://docs.mongodb.com/drivers/php/ to use old style nice new \MongoDB\Client('mongodb://127.0.0.1');

answered Jun 16, 2021 at 22:05

Class mongodb client not found

user956584user956584

5,0112 gold badges38 silver badges47 bronze badges