mongodb / laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel (Moloquent)
https://www.mongodb.com/compatibility/mongodb-laravel-integration
MIT License
6.99k stars 1.42k forks source link

Class 'MongoDB\Driver\Manager' not found #1358

Closed lzao closed 4 years ago

lzao commented 6 years ago

Hello, I'm using Php7.1, Laravel 5.5, and Mongo 3.4.10 as Dockers.

In the .../vendor/mongodb/mongodb/src/Client.php file, the corresponding FatalThrowableError Class 'MongoDB\Driver\Manager' not found appears on line 83.

In the Model

<? php

namespace App\Models\Mongo;

use Jenssegers\Mongodb\Eloquent\Model as Moloquent;

class Keywords extends Moloquent
{
     protected $connection = 'mongodb';
     protected $collection = 'keywords';
}

I used the code,

In the Controller,

public function keyword ()
{
     Keywords::all();
}

I used the code.

The database.php file contains

'mongodb' => [
     'driver' => 'mongodb',
     'host' => '127.0.0.1',
     'port' => '27017',
     'database' => 'test',
],

I put this code in it.

I've been looking for the same error since yesterday, but it's still the same. Help is urgently needed.

rkgarcia commented 6 years ago

Are you adding the ServiceProvider? Update your mongodb driver

Juli55 commented 6 years ago

For me the same problem, but in migration and seeding it works but not in the website

prog-24 commented 6 years ago

Duplicate of #1163

doliskani commented 5 years ago

iI have the same problem, please help me one

rkgarcia commented 5 years ago

@doliskani do you have the mongodb extension installed and activated?

doliskani commented 5 years ago

Yes I did. I use Laravel 5.7 and my php version is 7.2.4 and also mongodb extension is Thread Safe (TS) x64 version 1.5.3

rkgarcia commented 5 years ago

Please share the output of php -m command share more information about OS i suspect that you use Windows and you need the 32 bits versión of driver

doliskani commented 5 years ago

C:\wamp64\bin\php>php -m [PHP Modules] bcmath bz2 calendar Core ctype curl date dom exif fileinfo filter gd gettext gmp hash iconv imap intl json ldap libxml mbstring mysqli mysqlnd openssl pcre PDO pdo_mysql pdo_sqlite Phar readline Reflection session SimpleXML soap sockets SPL standard tokenizer wddx xml xmlreader xmlrpc xmlwriter xsl zip zlib

[Zend Modules]

I don't understand why it does't display Mongo at here but it is shown in the output of the phpinfo()

a

rkgarcia commented 5 years ago

Please follow the issues:

1358

761

1163

1093

doliskani commented 5 years ago

None of the above links resolved my issue I installed jenssegers as follows : composer require jenssegers/mongodb --ignore-platform-reqs Can it help to solve?

doliskani commented 5 years ago

I can store the information using the command line, but I can't in Laravel, where is the problem? and i added Jenssegers\Mongodb\MongodbServiceProvider::class, in service provider

rkgarcia commented 5 years ago

Please install without the --ignore-platform-reqs, please share the output of command php --ini

doliskani commented 5 years ago

capture Thanks

doliskani commented 5 years ago

I'm really helpless, why this error does not fix

rkgarcia commented 5 years ago

I'm really helpless, why this error does not fix

You need to update your mongodb extension.

aanimation commented 5 years ago

hi all, i was trial and error how to find solutions Class 'MongoDB\Driver\Manager' not found i just flow the machine (macbook air with mojave), MAMP + php7.1.19, another php installed 7.2.7, but in MAMP i used 7.1.19 as default.

First problem : i cant do composer install/update, since use jenssegers/mongodb, machine said, i need an extension for mongodb support, First solved : research how to install this extension to my default php installed. solved by (http://php.net/manual/en/mongodb.installation.manual.php) `Manually Installing the MongoDB PHP Driver

$ git clone https://github.com/mongodb/mongo-php-driver.git $ cd mongo-php-driver $ git submodule update --init $ phpize $ ./configure $ make all $ sudo make install`

If you have problem with configure, just do : $ brew install autoconf

then i check file mongodb.so in php/php7.1.19/lib/php/extensions/no-debug-non-zts-20160303 has already created.

i check php.ini too (php/pph7.1.19/conf), make sure that extension. But I remember I was wrote this line before (another research) : 
extension=mongodb.so in ; Extensions groups. 
I just double check.



Second problem, I check phpinfo in browser, I’m not find word as mongo, I’m little frustate. Huuftt. Ok, I check php -m in terminal, no mongo found too.

Im going to try run mongod in terminal. Then recheck last action : phpinfo + php -m. Result shown me more frustation.

The research (mac) : I found in folder php/pph7.1.19/conf there are files :

OK..I wrote a line extension for mongo too, like before. Then restart server (in MAMP) & check phpinfo : mongodb show detailed. I think I was success then happy,

Back to terminal and check php -m, no mongo again. Huuuft

i research by delete temp file (backup before) then do some last step, but not working, so i restore file and recheck

Final Wait…I check php —ini result:
Configuration File (php.ini) Path: /Applications/MAMP/bin/php/php7.1.19/conf Loaded Configuration File: /Library/Application Support/appsolute/MAMP PRO/conf/php7.1.19.ini Loaded conf different with conf file.

so…I get this file, to add line extension=mongodb.so, I hope this make sense.

Result Restart server and re-check like before, hahahahaha… mongo is running. Phpinfo and php module should be show mongo

NOTE : mongod still running on other tab in terminal. You can check in browser as http://127.0.0.1:27017/

To make sure mongodb already in machine what I expected for my app (Laravel 5.6 + postgre + mongodb for logging).

php artisan migrate:fresh —seed get successfull.

btw..thanks for all, for comments.

Im a amateur for this case, im newbie for Mac, this first half-year using Mac-OS. I hope some friends can explain in advanced. 👯‍♂️

sorry late, composer update successfull while mongo client was running, http://127.0.0.1:27017/ shown It looks like you are trying to access MongoDB over HTTP on the native driver port.

devenpateldp commented 5 years ago

Laravel Version: 5.7 PHP Version:7.1 Laravel-admin: latest

After first installing https://github.com/jenssegers/laravel-mongodb

Symfony \ Component \ Debug \ Exception \ FatalThrowableError (E_ERROR) Call to a member function prepare() on null

Symfony\Component\Debug\Exception\FatalThrowableError …/vendor/laravel/framework/src/Illuminate/Database/Connection.php326

vendor/laravel/framework/src/Illuminate/Database/Connection.php

any solution?

Messhias commented 4 years ago

I'm facing the same issue and this doesn't have any direct relation with your PHP Mongo DB driver, I'm running the project inside a docker self container environment and the issue still happening (I'm running the composer inside the same Docker context).

I'm using PHP 7.4 with Laravel's latest version.

When I downgraded to PHP 7.1 it worked fine.

I guess the issue there's a relation with PHP version itself than with MongoDB, anyway, this does not only happen when I do composer require it's happening too when I tried to do composer update.

This issue is very common with this library and usually, my solutions are going to the core of the library and change everything by myself and sometimes when I run the composer <require/update/remove> --ignore-platform-reqs works.

The issue in my case is on the file vendor/mongodb/mongodb/src/Client.php line 107 on the constructor function, code bellow:

public function __construct($uri = 'mongodb://127.0.0.1/', array $uriOptions = [], array $driverOptions = [])
    {
        $driverOptions += ['typeMap' => self::$defaultTypeMap];

        if (isset($driverOptions['typeMap']) && ! is_array($driverOptions['typeMap'])) {
            throw InvalidArgumentException::invalidType('"typeMap" driver option', $driverOptions['typeMap'], 'array');
        }

        $this->uri = (string) $uri;
        $this->typeMap = isset($driverOptions['typeMap']) ? $driverOptions['typeMap'] : null;

        unset($driverOptions['typeMap']);

        $this->manager = new Manager($uri, $uriOptions, $driverOptions);
        $this->readConcern = $this->manager->getReadConcern();
        $this->readPreference = $this->manager->getReadPreference();
        $this->writeConcern = $this->manager->getWriteConcern();
    }

For some reason, the Driver Manager is gone (and I tried to search and the driver is really gonne, why removed?!).

Anyway, for now, the only solution it seems like we have to downgrade to 3.5 and wait for the fix.

Smolevich commented 4 years ago

@Messhias show example for docker-compose configuration and steps for reproducing problem

Messhias commented 4 years ago

@Messhias show example for docker-compose configuration and steps for reproducing problem

Do you mean you need the Dockerfile configuration?

Smolevich commented 4 years ago

@Messhias show example for docker-compose configuration and steps for reproducing problem

Do you mean you need the Dockerfile configuration?

Yes and versions for php mongo driver and extension

Messhias commented 4 years ago

@Messhias show example for docker-compose configuration and steps for reproducing problem

Do you mean you need the Dockerfile configuration?

Yes and versions for php mongo driver and extension

@Smolevich All the necessary information you can found out in my dev Dockerfile, unfortunately, I cannot share the production one as per classified issues, but the only difference between the 2 files are the ENV vars which there's no relation with the issue that we're facing right now.

In fact, I strongly suggest use this Dockerfile in future versions of the library but this is the one that I use when the library broken or some unfixed issue happens to debug by myself and change the core.

FROM devilbox/php-fpm-7.4:latest

# opcache configurations.
ENV PHP_OPCACHE_VALIDATE_TIMESTAMPS="1" \
    PHP_OPCACHE_MAX_ACCELERATED_FILES="33531" \
    PHP_OPCACHE_MEMORY_CONSUMPTION="2048" \
    PHP_OPCACHE_MAX_WASTED_PERCENTAGE="10" \
    PHP_OPCACHE_FILE_OVERRIDE=1

# updating the S.O.
RUN apt-get update

# installing the apt-utils package.
RUN apt-get update -y && apt-get install -y --no-install-recommends apt-utils

# installing the pdf libraries.
RUN ln -s /usr/local/bin/wkhtmlto /usr/bin/wkhtmltopdf
RUN apt-get install -y xvfb libfontconfig wkhtmltopdf

# getting the dependencies
RUN apt-get install -y zlib1g-dev \
    libjpeg-dev \
    libpng-dev \
    libfreetype6-dev \
    libreadline-dev \
    libjpeg62-turbo-dev \
    libonig-dev \
    build-essential \
    libzip-dev

# updating the dependencies.
RUN apt-get update -y

# Install Dependencies
RUN ACCEPT_EULA=Y apt-get install -y \
    unixodbc \
    unixodbc-dev \
    libgss3 \
    odbcinst \
    locales \
    && echo "en_US.UTF-8 UTF-8" > /etc/locale.gen && locale-gen

RUN ln -s /usr/lib/x86_64-linux-gnu/libsybdb.a /usr/lib/

RUN apt-get update -y \
    && apt-get install -y libmcrypt-dev \
    && rm -rf /var/lib/apt/lists/* \
    && pecl install mcrypt-1.0.2 \
    && docker-php-ext-enable mcrypt

# turning on the extensions
RUN docker-php-ext-install gd
RUN docker-php-ext-install opcache

# install mongodb library
RUN apt-get update -y
RUN apt-get -y install gcc make autoconf libc-dev pkg-config libssl-dev
RUN pecl install mongodb
RUN docker-php-ext-install bcmath
RUN echo "extension=mongodb.so" >> /usr/local/etc/php/conf.d/mongodb.ini

# Install Laravel dependencies
RUN docker-php-ext-install iconv mbstring \
    && docker-php-ext-install zip \
    && docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
    && docker-php-ext-install gd

# enable the redis extension.
RUN pecl install -o -f redis \
    &&  rm -rf /tmp/pear \
    &&  docker-php-ext-enable redis

# copying custom php.ini configurations into the container.
COPY docker/php/conf.d/opcache.ini /usr/local/etc/php/conf.d/opcache.ini

# adding the bmacth extension for telescope watcher
RUN docker-php-ext-install bcmath

# creating the working DIR
RUN mkdir -p /code
ENV HOME=/code
WORKDIR $HOME

# setting the default user into the working dir
USER root
COPY ./ $HOME
Messhias commented 4 years ago

Any updates about this issue?

Smolevich commented 4 years ago

@Messhias notify me in here or slack community(Link here) tomorrow

Messhias commented 4 years ago

@Smolevich let's continue this discussion by slack and let's hope to @jenssegers accept the propose.

divine commented 4 years ago

Hello,

This has nothing to do with this library, it's an issue with missing/incorrect settings for mongodb extension. For more information see: https://jira.mongodb.org/browse/PHPC-656

Thanks.

Kistlak commented 4 years ago

If you get this error, even after you installed the Mongodb driver for php, just install mongodb using composer.

composer require mongodb/mongodb

After that this will solve your problem.

webmaster-hm commented 4 years ago

I had the same issue. I have solved it changing the permissions on the library mongodb.so, because after the installation the file had 644 and I changed to 755 and it worked.

cybusnoor commented 3 years ago

I had the same issue and the following two commands solved my issue

sudo apt-get install php-mongodb

sudo service apache2 restart

AngusDV commented 2 years ago

i am have a same issue

php7.3 -m
PHP Warning:  PHP Startup: Unable to load dynamic library 'mongodb.so' (tried: /usr/lib/php/20180731/mongodb.so (/usr/lib/php/20180731/mongodb.so: undefined symbol: ns_parserr), /usr/lib/php/20180731/mongodb.so.so (/usr/lib/php/20180731/mongodb.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
[PHP Modules]
calendar
Core
ctype
date
dom
exif
fileinfo
filter
ftp
gd
gettext
hash
iconv
intl
json
libxml
mysqli
mysqlnd
openssl
pcntl
pcre
PDO
pdo_mysql
Phar
posix
readline
Reflection
session
shmop
SimpleXML
sockets
sodium
SPL
standard
sysvmsg
sysvsem
sysvshm
tokenizer
wddx
xml
xmlreader
xmlwriter
xsl
Zend OPcache
zip
zlib

[Zend Modules]
Zend OPcache
meshackjr commented 2 years ago

If your using valet, restart it after installation.

KR-CHOUDHARY commented 8 months ago

Class "MongoDB\Driver\Manager" not found this error new laravel Version please help me my new error in terminal error this PHP Warning: PHP Startup: Unable to load dynamic library 'mongodb' (tried: C:\xampp\php\ext\mongodb (The specified module could not be found), C:\xampp\php\ext\php_mongodb.dll (The specified module could not be found)) in Unknown on line 0 php version PHP 8.2.4 laravel version latest

latifaChakir commented 5 months ago

did you fixed this problem!

KR-CHOUDHARY commented 5 months ago

yes

On Tue, Apr 2, 2024 at 5:56 AM latifaChakir @.***> wrote:

did you fixed this problem!

— Reply to this email directly, view it on GitHub https://github.com/mongodb/laravel-mongodb/issues/1358#issuecomment-2030844725, or unsubscribe https://github.com/notifications/unsubscribe-auth/A75FUI2J2IWTFPZ3X7DI5MLY3H3JTAVCNFSM4ECQP7O2U5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TEMBTGA4DINBXGI2Q . You are receiving this because you commented.Message ID: @.***>