I have added the latest php_mongodb.dll compatible with PHP 8.2 in XAMPP. I'm using Mongo DB Package with Laravel 10 as mentioned in their documentation.
mongodb/laravel-mongodb
When I start my server I get InvalidArgumentException Driver [mongodb] not supported.
My config/database.php
'default' => env('DB_CONNECTION', 'mongodb'),
'mongodb' => [
'driver' => 'mongodb',
'dsn' => env('DB_URI', 'mongodb+srv://username:password@<atlas-cluster-uri>/myappdb?retryWrites=true&w=majority'),
'database' => env('DB_DATABASE', 'abc'),
]
My config/session.php
return [
'driver' => 'mongodb',
'connection' => 'mongodb',
'collection' => 'sessions',
'lifetime' => 120,
'expire_on_close' => false,
'encrypt' => false,
'files' => storage_path('framework/sessions'),
'lottery' => [2, 100],
'cookie' => env(
'SESSION_COOKIE',
Str::slug(env('APP_NAME', 'laravel'), '_').'_session'
),
'path' => '/',
'domain' => env('SESSION_DOMAIN', null),
'secure' => env('SESSION_SECURE_COOKIE', false),
'http_only' => true,
];
I have also added following provider in config/app.php
'providers' => [
/*
* Laravel Framework Service Providers...
*/
Illuminate\Auth\AuthServiceProvider::class,
Illuminate\Broadcasting\BroadcastServiceProvider::class,
Illuminate\Bus\BusServiceProvider::class,
Illuminate\Cache\CacheServiceProvider::class,
Illuminate\Foundation\Providers\ConsoleSupportServiceProvider::class,
Illuminate\Cookie\CookieServiceProvider::class,
Illuminate\Database\DatabaseServiceProvider::class,
Illuminate\Encryption\EncryptionServiceProvider::class,
Illuminate\Filesystem\FilesystemServiceProvider::class,
Illuminate\Foundation\Providers\FoundationServiceProvider::class,
Illuminate\Hashing\HashServiceProvider::class,
Illuminate\Mail\MailServiceProvider::class,
Illuminate\Notifications\NotificationServiceProvider::class,
Illuminate\Pagination\PaginationServiceProvider::class,
Illuminate\Pipeline\PipelineServiceProvider::class,
Illuminate\Queue\QueueServiceProvider::class,
Illuminate\Redis\RedisServiceProvider::class,
Illuminate\Auth\Passwords\PasswordResetServiceProvider::class,
Illuminate\Session\SessionServiceProvider::class,
Illuminate\Translation\TranslationServiceProvider::class,
Illuminate\Validation\ValidationServiceProvider::class,
Illuminate\View\ViewServiceProvider::class,
Barryvdh\DomPDF\ServiceProvider::class,
MongoDB\Laravel\MongoDBServiceProvider::class,
Error Log
local.ERROR: Driver [mongodb] not supported. {"exception":"[object] (InvalidArgumentException(code: 0): Driver [mongodb] not supported. at ****\\vendor\\laravel\\framework\\src\\Illuminate\\Support\\Manager.php:109)
[stacktrace]
#0 ****\\vendor\\laravel\\framework\\src\\Illuminate\\Support\\Manager.php(80): Illuminate\\Support\\Manager->createDriver('mongodb')
#1 ****\\vendor\\laravel\\framework\\src\\Illuminate\\Session\\Middleware\\StartSession.php(159): Illuminate\\Support\\Manager->driver()
#2 ****\\vendor\\laravel\\framework\\src\\Illuminate\\Session\\Middleware\\StartSession.php(57): Illuminate\\Session\\Middleware\\StartSession->getSession(Object(Illuminate\\Http\\Request))
#3 ****\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(183): Illuminate\\Session\\Middleware\\StartSession->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#4 ****\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(119): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#5 ****\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Kernel.php(175): Illuminate\\Pipeline\\Pipeline->then(Object(Closure))
#6 ****\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Kernel.php(144): Illuminate\\Foundation\\Http\\Kernel->sendRequestThroughRouter(Object(Illuminate\\Http\\Request))
#7 ****\\public\\index.php(53): Illuminate\\Foundation\\Http\\Kernel->handle(Object(Illuminate\\Http\\Request))
#8 {main}
"}
The error "Driver [mongodb] not supported" typically occurs in Laravel when you attempt to use a database driver that is not supported or configured properly. To resolve this issue and use MongoDB as the database driver in Laravel 10, you need to ensure that you have configured Laravel to use MongoDB properly. Here's how you can do it:
Install MongoDB PHP Extension: Ensure that the MongoDB PHP extension is installed and enabled in your PHP environment. You can install it using PECL or your package manager.
Install Laravel MongoDB Package: Laravel does not have built-in support for MongoDB out of the box. You need to use a third-party package that provides MongoDB support. One popular package is jenssegers/laravel-mongodb. Install it via Composer:
Configure Laravel to Use MongoDB: Update your Laravel database configuration to use MongoDB. Open your .env file and configure the database connection settings for MongoDB:
Adjust the host, port, database name, username, and password as per your MongoDB setup.
Set Up Models: Create Eloquent models for your MongoDB collections as you would for relational databases. Ensure that your models extend Jenssegers\Mongodb\Eloquent\Model.
Use MongoDB-specific Functions: When working with MongoDB, you may need to use MongoDB-specific functions for querying and interacting with the database. Refer to the documentation of jenssegers/laravel-mongodb for more details on how to use MongoDB functionality in Laravel.
Clear Configuration Cache: If you've made changes to your configuration, remember to clear the configuration cache:
After following these steps, you should be able to use MongoDB as the database driver in Laravel 10 without encountering the "Driver [mongodb] not supported" error. Make sure to refer to the documentation of jenssegers/laravel-mongodb for detailed usage instructions and best practices.