Fatal Error: Class 'Mongodb\Driver\Manager' Not Found

Fatal error: Class 'MongoDB\Driver\Manager' not found

There is some confusion between the Mongo extension and the MongoDB extension which are not the same. Because of your version number, I guess you are using the old Mongo extension that is deprecated.

Make sure that you install the new MongoDB extension and you should be fine. Don't forget to remove the old extension=mongo.so from your php.ini since this could cause problems.

MongoDB\Driver\Manager' not found with php

"Console" and "Web" are using two different PHP binaries (and configurations).

Put the extension=php_mongodb.dll also in the so called php-cli version php.ini and the problem should be solved.

Class 'MongoDB\Driver\Manager' not found Even if php-mongo has been installed

I didn't solve the problem eventually. But I removed built-in apache2 and PHP then reinstalled them by brew instead. This time I chose apache24 and php70, also turned to php70-mongodb rather than 5.5's.

By the way, I'm sure that is the problem caused by the package not being installed correctly or setting wrong. But I didn't solve problem toward that way. I chose another (install other versions) instead.

1. Remove built-in apache

Let apache stop
sudo apachectl stop
Remove built-in apache
sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist 2>/dev/null

2. Install packages by Homebrew

Install apache (apache is called httpd)
brew install httpd24
Install php 7
brew install php70 --with-apache
Install PHP driver of MongoDB
brew install php70-mongodb --with-apache

3. Restart apache

sudo apachectl restart

Class 'MongoDB\Driver\Manager' not found (extension not loaded)

Solution: I was using a 64-bit dll which was incompatible with the 32-bit xampp which was running php. Simply remove the 64-bit dll and download the 32-bit version.

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

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
)

)


Related Topics



Leave a reply



Submit