laravel Mongodb 数据库上的 SASL 身份验证失败
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32785910/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SASL Authentication failed on Mongodb database
提问by juanObrach
I-m having an issue trying connect to Mongodb using PHP Mongodb driver.
我在尝试使用 PHP Mongodb 驱动程序连接到 Mongodb 时遇到问题。
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:
实际上,我有一个名为 LRS 的数据库,它有一个名为“juano”的用户,在我的设置文件中带有 pwd:“12345” 我确定我编写了正确的配置。但是当我在 Laravel 中加载我的主页时,我收到了这条消息:
MongoConnectionException (71)
HELP
Failed to connect to: localhost:27017: SASL Authentication failed on database'LRS': Authentication failed.
More specific the error found here
更具体的错误发现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'
],
]
];
回答by juanObrach
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.
对不起,伙计们,我觉得自己很愚蠢,因为问题是我在本地机器上启动了 mongod,然后我将我的网络运行到了虚拟机中。因此,在我的数据库连接配置文件中,我在服务器字段中写了“localhost”。
回答by HEMAL
Please check
请检查
.env
.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
感谢和问候