Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

php

mongodb

I want to use the MongoDB Driver, but it throw me an error, when i use it:

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

The error:

Message: Class 'MongoDB\Driver\Manager' not found

When i check it with the php_info(), i see, there is enter image description here

Is there any requirement to use the driver?

like image 855
tthlaszlo Avatar asked Aug 04 '16 11:08

tthlaszlo


3 Answers

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.

like image 57
simon Avatar answered Nov 10 '22 21:11

simon


For me, I forgot to add extension=mongodb.so to the php.ini for FPM (FastCGI Process Manager). On Ubuntu 16.04 this was at:

/etc/php/7.0/fpm/php.ini

For what it's worth I'm using nginx.

like image 24
Ryan DuVal Avatar answered Nov 10 '22 21:11

Ryan DuVal


1.Add mongo DB

$sudo apt update && sudo apt install php-mongodb
  1. Restart apache server,

  2. check in phpinfo() for mongo

like image 10
abhishek kumar Avatar answered Nov 10 '22 22:11

abhishek kumar