【问题标题】:Connect to MongoDB with authorization通过授权连接到 MongoDB
【发布时间】:2014-05-06 00:03:20
【问题描述】:

我在 MongoDB 中创建了以下用户

/* 1 */
{
    "_id" : ObjectId("5368247553e1d8650fdee0d1"),
    "user" : "userName",
    "pwd" : "3d8540469xxxxxxxxxxxxxxx28fbf8b76",
    "roles" : [ 
        {
            "role" : "userAdminAnyDatabase",
            "db" : "admin"
        }
    ]
}

现在我正在尝试连接到我的远程 MongoDB 实例

>mongo --host 10.0.0.1 --port 27017 --username username --password password

我得到以下错误

errmsg: auth failed 
code: 18
exception: login failed

我不确定出了什么问题。如果我在我的配置文件中禁用授权并重新启动我的副本集实例,我可以正确连接。

解决方案:

使用以下用户角色

【问题讨论】:

  • @whoeverDownvoted,请随时分享您认为这个问题的错误之处,以便我更正我的问题。
  • 如果您专门连接到管理数据库(而不是测试)会发生什么?将单词 admin 添加到 mongo 命令行的末尾。

标签: windows mongodb authentication mongo-shell


【解决方案1】:

试试这个

mongo -u yourUser -p yourPwd --authenticationDatabase admin

【讨论】:

    【解决方案2】:

    使用

    mongo --port 27017 -u 用户名 -p pas

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-18
      • 2018-04-22
      • 1970-01-01
      • 2020-04-16
      • 1970-01-01
      • 2020-02-18
      相关资源
      最近更新 更多