jcaruso jcaruso - 1 month ago 17
PHP Question

PHP 'MongoClient' Not Found

There are tons of questions on this topic, but none of them have worked for me. I originally had the mongodb driver installed (and working) using

sudo pecl install mongo


however according to the pecl output this has been deprecated and replaced with

sudo pecl install mongodb


So I installed that, changed
mongo.ini
to load
extension=mongodb.so
instead of
mongo.so
(as instructed to by the output of the above
pecl
command) . When I load my phpinfo() page it shows that it is loaded

mongodb version 1.0.0
mongodb stability stable
libmongoc version 1.2.0
libbson version 1.2.0


However, when I try to use MongoClient in my PHP page, I get the following error:

Fatal error: Class 'MongoClient' not found in /srv/www/site/functions.php on line 500


I have exhausted all of the 'similar questions' suggested when creating this question, as well as google searches. So I'm hoping someone has some first-hand experience with fixing this because I feel like I'm out of options.

Answer

Turns out the class names have changed in the new driver. So MongoClient not existing is a valid error.

new MongoDB\Driver\Manager is the replacement for MongoClient