-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Class 'MongoClient' not found? #36
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
Does this only happen when using migrations? Because MongoClient is the native PHP class. |
Looks like an issue with the php-mongo extension not being loaded by PHP. Check phpinfo() and see if the Mongo extension is being loaded, if not check your php.ini file or load the extension through a separate mongo.ini file in conf.d |
What is I get the same error (Class 'MongoClient' not found) but Mongo is enabled within PHP. Any idea? |
Same problem @cloud-ops |
Can you create an instance of MongoClient without this library? I don't think this error is related to this library, but with your Mongo installation. |
Yes! I fixed it. |
Thanks @brunocascio , you last (above) comment was very helpful 😄 |
There is also a new project that is creating a MongoDB driver that you can include using composer: https://github.com/mongofill/mongofill But I have not tested it yet. |
Same here @brunocascio, that last comment helped me too, thanks 😸 |
Same here @brunocascio, your last comment helped me. |
@jenssegers I am getting this same error. I have confirmed via a phpinfo() statement that the Mongo driver has loaded |
My experience using Ubuntu is that once the PHP MongoDB driver is correctly installed you will have to add the line I had the exact error and that is what solved it for me. |
If your "php -i" shows that Mongo enabled, but you're still getting the same error, that means you need to restart something. Lost a few hours before it downed on me to restart php-fpm. Solution for php-fpm (Ubuntu):
As you have now have two declaration "extension=mongo.so", it would be better to comment line "extension=mongo.so" in your php.ini |
It can be a Mongo integration problem, but if it isn't, and if like me, you are using native MongoDB commands with PHP, try to put a backslashe before the class, like so: "\MongoClient()" |
I had the same problem . after I upgraded my Yosemite to 10.10.5 . all answers above did not solved my problem . my php --ini displayed that the mongo drive is loaded . But still got the error . |
Thanks man. I am using Linux Mint. To solve this issue i added "extension=mongo.so" (Without quotes) in two directories -
|
I have same problem on php new release, 7.0.2 . it has no mongoClient anymore and uses mongoDB extension! Now how can I use jenssegers/laravel-mongodb in my new server? please help about this asap. |
@a-ghasemi There's a separate branch for this. Will be released as a new major version soon. |
Thanks for your afforts
|
is there expected release date for support mongodb 3.2? |
@mvladk Version 2.3.x works well with mongodb 3.2. |
@jenssegers I see your 3.0 branch that uses mongodb pecl extension but I can't figure out how to install this with composer. if I put in "3.*" in my composer.json it yells at me because you haven't released it yet. How might I be able to use this or is there a release date for this? |
@jensk it might work well with mongodb 3.2 but php 7 now uses a new pecl extension called "mongodb" instead of "mongo" and this is causing the "MongoClient not found" error. That is what he is talking about. |
@bgarrison25 Use the master branch.
I think the 3.0 version is not finished yet. I use the master branch to do all my test before shipping to php7 server. The "MongoClient not found" is because you are using a old mongo client. I had a diferente issue, but I guess you can get rid of this message, compiling _libmongoc_ again, and installing the mongo client via pecl. Look up mongodb/mongo-php-driver#219 (comment) |
@bgarrison25 Indeed, php 7 requires a new driver called mongodb. (only supported by the current master branch, no release yet) Though, in my post I just answered the question about mongodb 3.2 support. ;-) |
@bgarrison25, exactly. finally it some how worked with "mongodb" and composer |
@mvladk - thank you. Upgrading composer to ~3.0 jenssegers/mongodb fixed it for me. Running Windows + php 7.0.1 + mongodb 3.2.1 composer.json php -i | grep The versioning is from: Some tips:
|
The following php code runs fines on command line, but it failed to open in browser, with error class not found. There's one possible cause is that even the phpinfo() page shows /etc/php-zts.d/mongodb.ini is loaded, but it doesn't show anything else for mongodb module, the mongodb.so file is already defined in the ini file, spent long time can't figure out the reason, pls advise how to proceed? Fatal error: Class 'MongoDB\Driver\Manager' not found in /var/www/vendor/mongodb/mongodb/src/Client.php on line 56 test.php demo->beers; $result = $collection->insertOne( [ 'name' => 'Hinterland', 'brewery' => 'BrewDog' ] ); echo "Inserted with Object ID '{$result->getInsertedId()}'"; ?> |
For all having problems with MongoClient function on php7 please check the following link: Basically as php7 uses a new driver class for MongoDB they has changed the function to be called. |
Having the same issue as @goopter. Lets revisit this issue here on github please |
Thanks to @Rents answer I fixed this issue. |
I do not know but all the things above did not work for me. Here is my workaround: Install MongoDB client Install MongoDB driver for PHP If you come across with sudo apt-get install libsasl2-dev for CentOS: |
I have the same problem on homestead with php 5.6 - laravel give me the same error but strange thing is I can work with mongo in php artisan tinker and I can migrate but in browser it shows : Class 'MongoDB\Driver\Manager' not found. I'm using "jenssegers/mongodb": "^3.1", in my composer.json file. |
i got the error as Fatal error: Class 'Mongoclient' not found in D:\xampp\htdocs\mongo.php on line 3 |
Hi! For those who use vagrant/homestead (also different versions of jenssegers/mongodb for two projects on one homestead)and as I stumbled on this problem, my solution will be useful. So, homestead (6.4.0) use php cli 7.1 as default and command 'php artisan' run by default cli. So if you face 'MongoClient' problem, that means you use not right cli version. In order to use right cli version you have to specify 'php5.6 artisan' or 'php7.1 artisan'. Also you must have right extension in php.ini. mongo.so - for old projects, mongodb.so - for new projects. |
Class 'MongoClient' not found in Connection.php on line 132. This is the error received when I try to run migrations - ($ php artisan migrate). Any Ideas? Thanks in advance.
The text was updated successfully, but these errors were encountered: