Reputation: 61
I am planning to use MongoDb along with my Laravel project. I am using the jensseger/mongodb extension for it. I have configured everything. I am getting an error saying mongodb not configured. This is how my database.php file looks like:
'connections' => [
# Our primary database connection
'mongodb' => [
'driver' => 'mongodb',
'host' => env('DB_HOST'),
'database' => env('DB_DATABASE'),
'username' => env('DB_USERNAME'),
'password' => env('DB_PASSWORD'),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
],
Upvotes: 1
Views: 7664
Reputation: 1
'mongodb' => [
'driver' => 'mongodb',
'host' => env('MONGO_DB_HOST', 'localhost'),
'port' => env('MONGO_DB_PORT', 27017),
'database' => env('MONGO_DB_DATABASE'),
'username' => env('MONGO_DB_USERNAME'),
'password' => env('MONGO_DB_PASSWORD'),
'options' => ['database' => 'Database_Name']
],
After clear cache "php artisan config:cache"
Upvotes: 0
Reputation: 1
go to .env Add these lines:
MONGO_DB_HOST=127.0.0.1
MONGO_DB_PORT=27017
MONGO_DB_DATABASE=your database name
MONGO_DB_USERNAME=your database username if you have
MONGO_DB_PASSWORD=your database password if you have
Upvotes: -1
Reputation: 308
Double check your configuration in config/database.php
Also make sure that you fire php artisan config:cache after doing the changes.
Upvotes: 4
Reputation: 409
Be sure to have DB_CONNECTION=mongodb
set in your .env file or just replace 'default' => env('DB_CONNECTION', 'mysql')
with 'default' => 'mongodb'
. I would go with the former, as it's safer to rely only on the .env, rather than hardcoding your default database connection.
Upvotes: 0