doutangtan6386 2017-09-05 14:11
浏览 311


I have a sharded MongoDB setup.

I'm trying to connect to it from my Laravel application

Before I sharded my database I was using laravel-mongodb to connect to my regular mongodb instance.

This was my previous config

'mongodb' => array(
        'driver'   => 'mongodb',
        'host'     => env('MONGODB_HOST', 'localhost'),
        'port'     => env('MONGODB_PORT', 27017),
        'username' => env('MONGODB_USERNAME', ''),
        'password' => env('MONGODB_PASSWORD', ''),
        'database' => env('MONGODB_DATABASE', ''),
        'options' => array(
            'db' => env('MONGODB_AUTHDATABASE', '') //Sets the auth DB

I tried to update the MONGODB_HOST to the sharded query router hostname but I am now getting the error

[MongoConnectionException] Failed to connect to: Authentication failed on database 'admin' with username 'maxrosecollins': auth failed`

I can see in the logs on the server

2017-09-05T14:42:36.558+0000 I NETWORK [thread2] connection accepted from #41615 (1 connection now open) 2017-09-05T14:42:36.560+0000 I ACCESS [conn41615] authenticate db: admin { authenticate: 1, user: "maxrosecollins", nonce: "xxx", key: "xxx" }

2017-09-05T14:42:36.562+0000 I ACCESS [conn41615] Failed to authenticate maxrosecollins@admin with mechanism MONGODB-CR: AuthenticationFailed: MONGODB-CR credentials missing in the user document

2017-09-05T14:42:36.563+0000 I - [conn41615] end connection (1 connection now open)

I can connect to the query router using the following. This is on the same server I am getting the auth failed error when using laravel. I have double checked passwords and usernames

mongo -u "maxrosecollins" -p "password" --authenticationDatabase "admin"
  • 写回答

2条回答 默认 最新

  • douluolan9101 2017-09-12 09:43

    I worked out my laravel-mongodb install was version 2 which doesn't support the SCRAM-SHA-1 authentication mechanism.

    I used composer updateto upgrade to version 3 which also meant upgrading the php mongo adapter along with a lot of other dependencies.

    I then ran db.adminCommand({authSchemaUpgrade: 1}); see upgrading auth

    After this I could authenticate with my mongo query router

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
  • doudou5101 2017-09-07 21:22
    'connections' => [
         'mongodb' => [
          'driver'   => 'mongodb',
          'dsn' => 'mongodb://,,',
          'database' => 'homestead',

    i can connect like this to my cloud atlas




  • ¥100 QT Open62541
  • ¥15 stata合并季度数据和日度数据
  • ¥15 c语言练习:统计词频
  • ¥15 谁能提供rabbitmq,erlang,socat压缩包,记住版本要对应
  • ¥15 Vue3 中使用 `vue-router` 只能跳转到主页面?
  • ¥15 用QT,进行QGIS二次开发,如何在添加栅格图层时,将黑白的矢量图渲染成彩色
  • ¥50 监控摄像头 乐橙和家亲版 保存sd卡的文件怎么打开?视频怎么播放?
  • ¥15 Python的Py-QT扩展库开发GUI
  • ¥60 提问一下周期性信信号的问题
  • ¥15 jtag连接不上fpga怎么办