【问题标题】:Unable to connect to mongodb in shell and with mongoose. Working with Robo3T无法在 shell 和 mongoose 中连接到 mongodb。使用 Robo3T
【发布时间】:2018-04-01 07:00:00
【问题描述】:

大家好,我的命令似乎有问题。 我可以使用 Robo 3T 连接到我的 mongodb。 但是,如果我制作一个连接字符串,例如。

let url = mongodb://root:PASSWORD@10.0.1.185:27017/tbAuth

mongoose.connect(url, { auto_reconnect: true })
        .catch((err) => {
            console.error('App starting error:', err);

错误:

App starting error: { MongoError: Authentication failed.
    at Function.MongoError.create (/var/app/current/node_modules/mongodb-core/lib/error.js:31:11)
    at /var/app/current/node_modules/mongodb-core/lib/connection/pool.js:489:72
    at authenticateStragglers (/var/app/current/node_modules/mongodb-core/lib/connection/pool.js:435:16)
    at Connection.messageHandler (/var/app/current/node_modules/mongodb-core/lib/connection/pool.js:469:5)
    at Socket.<anonymous> (/var/app/current/node_modules/mongodb-core/lib/connection/connection.js:321:22)
    at emitOne (events.js:116:13)
    at Socket.emit (events.js:211:7)
    at addChunk (_stream_readable.js:263:12)
    at readableAddChunk (_stream_readable.js:250:11)
    at Socket.Readable.push (_stream_readable.js:208:10)
    at TCP.onread (net.js:594:20)
  name: 'MongoError',
  message: 'Authentication failed.',
  ok: 0,
  errmsg: 'Authentication failed.',
  code: 18,
  codeName: 'AuthenticationFailed' }

或者如果我通过 ssh SSH 到服务器并尝试连接

mongo -u root -p PASSWORD

它失败了。

身份验证机制是 SCRAM-SHA-1 它明确指出这是一个身份验证错误。

MongoDB shell version v3.6.3
connecting to: mongodb://%2Fopt%2Fbitnami%2Fmongodb%2Ftmp%2Fmongodb-27017.sock/
MongoDB server version: 3.6.3
2018-03-31T22:44:44.238+0000 E QUERY    [thread1] Error: Authentication failed. :
DB.prototype._authOrThrow@src/mongo/shell/db.js:1608:20
@(auth):6:1
@(auth):1:2
exception: login failed

任何想法可能是什么问题?我已经删除了身份验证要求并重置了用户的密码,但它仍然失败.. 如果我删除身份验证要求,一切正常,因此服务器可以访问并且数据库正在运行。

服务器位于使用 bitnami 创建的 aws 上。

【问题讨论】:

    标签: node.js mongodb amazon-web-services bitnami


    【解决方案1】:

    如果自己找到答案。

    对于任何挣扎的人。请务必使用 sudo 并连接到管理员。

    sudo mongo admin --username root --password password
    

    对于猫鼬连接字符串:

    mongodb://root:PASSWORD@10.0.1.185:27017/tbAuth?authSource=admin
    

    ?authSource=admin 帮我解决了问题

    【讨论】:

      猜你喜欢
      • 2015-01-28
      • 2020-02-22
      • 2020-07-25
      • 1970-01-01
      • 2019-12-30
      • 1970-01-01
      • 2021-02-17
      • 1970-01-01
      • 2020-07-14
      相关资源
      最近更新 更多