我在尝试使用 PHP Mongodb 驱动程序连接到 Mongodb 时遇到问题。
实际上我有一个名为 LRS 的数据库,它在我的设置文件中有一个名为“juano”的用户,密码为:“12345”我确定我编写了正确的配置。 但是当我在 Laravel 中加载我的主页时,我收到了这条消息:
MongoConnectionException (71)
HELP
Failed to connect to: localhost:27017: SASL Authentication failed on database'LRS': Authentication failed.
更具体的是这里发现的错误
if (isset($config['password']) && $config['password'])
{
$options['password'] = $config['password'];
}
return new MongoClient($dsn, $options);
}
这是我的配置文件
<?php
return [
'connections' => [
'mongodb' => [
'driver' => 'mongodb',
'host' => 'localhost',
'port' => 27017,
'username' => 'juano',
'password' => '12345',
'database' => 'LRS'
],
]
];
最佳答案
抱歉,我觉得自己很愚蠢,因为问题是我在本地机器上启动了 mongod,然后我将我的网络运行到虚拟机中。 所以,在我的数据库连接配置文件中,我在服务器字段中写了“localhost”。
关于php - Mongodb 数据库上的 SASL 身份验证失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32785910/