【问题标题】:SASL Authentication failed on Mongodb databaseMongoDB 数据库上的 SASL 身份验证失败
【发布时间】:2015-10-29 16:18:29
【问题描述】:

我在尝试使用 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'
      ],
  ]
];

【问题讨论】:

    标签: php mongodb laravel mongodb-php


    【解决方案1】:

    对不起,我觉得自己很愚蠢,因为问题是我在本地机器上启动了 mongod,然后我将我的网络运行到了虚拟机中。 所以,在我的数据库连接配置文件中,我在服务器字段中写了“localhost”。

    【讨论】:

    • 非常感谢!阅读您的答案后,我找到了解决方案。只是为了完整性:在“/etc/mongod.conf”中,应该有:“net:bindIp:0.0.0.0”
    【解决方案2】:

    请检查

    .env

    laravela 中的文件

    在此处添加您的所有数据库配置详细信息并检查它并在添加后告诉我是否有任何问题。

    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
    

    感谢和问候

    【讨论】:

    • 因为他没有从他的配置中引用环境变量,所以它们是无关紧要的
    猜你喜欢
    • 1970-01-01
    • 2016-08-20
    • 1970-01-01
    • 2019-12-17
    • 1970-01-01
    • 2016-07-05
    • 2018-01-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多