Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Unsupported driver [mongodb] #2643

Answered by zyz954489346
saurabhrc15 asked this question in Q&A
Discussion options

I'm currently working with PHP (v8.1), Laravel/Lumen Framework (^10.0), MongoDB (v7.0.2), mongodb/laravel-mongodb(^4.0), mongodb/mongodb(^1.16) and Linux (v20.04). I've successfully installed the PHP MongoDB extension. I verified its installation for the CLI using the command php -m | grep mongodb, which returned "mongodb". Additionally, through phpinfo(), I confirmed that the MongoDB extension is enabled in the Apache web server.

For the Laravel-Lumen setup, I've learned that one should register MongoDB\Laravel\MongoDBServiceProvider::class before invoking $app->withEloquent(). However, when I attempt this, I encounter an error: "Call to a member function prepare() on null". Furthermore, a recurrent error I face states "Unsupported driver [mongodb]". I'm puzzled by these issues. Can someone shed some light on them and assist me?

bootstrap/app.php

<?php
require_once __DIR__.'/../vendor/autoload.php';
(new Laravel\Lumen\Bootstrap\LoadEnvironmentVariables(
 dirname(__DIR__)
))->bootstrap();
date_default_timezone_set(env('APP_TIMEZONE', 'UTC'));
$app = new Laravel\Lumen\Application(
 dirname(__DIR__)
);
$app->singleton(
 Illuminate\Contracts\Debug\ExceptionHandler::class,
 App\Exceptions\Handler::class
);
$app->singleton(
 Illuminate\Contracts\Console\Kernel::class,
 App\Console\Kernel::class
);
$app->configure('jwt');
$app->configure('api');
$app->configure('database');
$app->withFacades();
$app->withEloquent();
$app->middleware([
]);
$app->routeMiddleware([
]);
$app->register(App\Providers\AuthServiceProvider::class);
$app->register(Tymon\JWTAuth\Providers\LumenServiceProvider::class);
$app->register(App\Providers\DatabaseServiceProvider::class);
$app->register(MongoDB\Laravel\MongoDBServiceProvider::class);
$app->router->group([
 'namespace' => 'App\Http\Controllers',
], function ($router) {
 require __DIR__.'/../routes/web.php';
});
return $app;
You must be logged in to vote

I found the cause of the problem.
See this Provider:

If there is a package run "app('db')" or "app->make('db)" in its provider, before this code in laravel-mongodb package.
Because db is registered as a singleton,so the resolving function will not be executed again.
So mongodb cannot be properly bound to the Provider.

Replies: 1 comment 6 replies

Comment options

same bug, need fix

You must be logged in to vote
6 replies
Comment options

I found the cause of the problem.
See this Provider:
image

If there is a package run "app('db')" or "app->make('db)" in its provider, before this code in laravel-mongodb package.
Because db is registered as a singleton,so the resolving function will not be executed again.
So mongodb cannot be properly bound to the Provider.

Answer selected by saurabhrc15
Comment options

In the final analysis, it is because mongo is registered through resolving rather than through the make function.
This may be a BUG, but it's not clear why need to regist by resolving instead of make.

Comment options

Hi, thanks for finding this - do you have any suggestions about how to resolve it?

Comment options

I've explained the issue here: #2715 (comment)

Comment options

I temporarily solved the problem by modifying the loading order of providers in config/app.php, but this is only a temporary solution.
@spinalwiz
Here example:

'providers' => ServiceProvider::defaultProviders()->merge([
 // Ensure that conflicting packages load first
 Mnabialek\LaravelSqlLogger\Providers\ServiceProvider::class,
 // Application Service Providers
 App\Providers\AppServiceProvider::class
 // ...etc
 ])->toArray(),
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

AltStyle によって変換されたページ (->オリジナル) /