问题
I-m having an issue trying connect to Mongodb using PHP Mongodb driver.
Actually I have a database called LRS and it has a user called "juano" with a pwd:"12345" in my settings file I-m sure that I wrote the correct configuration. But when I load my homepage in Laravel I receive this message:
MongoConnectionException (71)
HELP
Failed to connect to: localhost:27017: SASL Authentication failed on database'LRS': Authentication failed.
More specific the error found here
if (isset($config['password']) && $config['password'])
{
$options['password'] = $config['password'];
}
return new MongoClient($dsn, $options);
}
And this is my config file
<?php
return [
'connections' => [
'mongodb' => [
'driver' => 'mongodb',
'host' => 'localhost',
'port' => 27017,
'username' => 'juano',
'password' => '12345',
'database' => 'LRS'
],
]
];
回答1:
Sorry guys, I-m feel stupid because the problem was I started mongod in my local machine and then I ran my web into a Virtual Machine. So, in my database connection config file I wrote "localhost" in the server field.
回答2:
Please check
.env
file in laravela
Add your all database configuration details here and check it & and let me know if any issue after adding.
APP_ENV=local
APP_DEBUG=true
APP_KEY= your key already given
DB_HOST=localhost
DB_DATABASE= your database here
DB_USERNAME= your username here
DB_PASSWORD= your password here
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync
MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
Thanks & Regards
来源:https://stackoverflow.com/questions/32785910/sasl-authentication-failed-on-mongodb-database