【问题标题】:MongoDB: Not authorized on admin to execute commandMongoDB:管理员未授权执行命令
【发布时间】:2018-04-06 13:18:54
【问题描述】:

当我使用show dbs 命令时,我的 mongo shell 给了我这个错误。

管理员无权执行命令

我尝试使用创建用户

db.createUser(
  {
    user: "siteUserAdmin",
    pwd: "password",
    roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]
  }
)

https://docs.mongodb.com/v2.6/tutorial/add-user-administrator/

但它仍然给我同样的错误:

无法添加用户:管理员未授权执行命令。

我使用的是 Ubuntu 16.04mongoDB 版本是 3.4.9

【问题讨论】:

    标签: mongodb ubuntu admin


    【解决方案1】:

    我认为您可以将该角色用作 Ubuntu 的 root。试试下面的查询。

    use admin
    db.createUser(
      {
        user: "admin",
        pwd: "password",
        roles: [ { role: "root", db: "admin" } ]
      }
    );
    exit; 
    

    你也可以给用户读写权限

    use admin
    
     db.grantRolesToUser("admin",["readWrite"])
    

    编辑

    由于上述方法不起作用,请尝试使用以下身份验证启动实例

    1. 停止 mongod 实例
    2. $ mongod --auth 启动实例
    3. 现在启动 mongo shell 并创建用户
       use admin
       db.createUser(
                {
                 user: "admin",
                 pwd: "password",
                 roles: [ { role: "root", db: "admin" } ]
                }
                    );
               exit;
    
    1. 现在给予许可

       db.auth("admin", "password")
       db.grantRolesToUser("password", [ { role: "readWrite", db: "admin" } ])
      
    2. 现在查看show users

    【讨论】:

    • @SLASH 使用 root 执行后遇到了什么错误
    • 我收到此错误:无法添加用户:管理员未授权执行命令
    • 这是整个事情错误:无法添加用户:管理员未授权执行命令{ createUser:“admin”,pwd:“xxx”,角色:[{角色: "root", db: "admin" } ], digestPassword: false, writeConcern: { w: "majority", wtimeout: 600000.0 } } : _getErrorWithCode@src/mongo/shell/utils.js:25:13 DB.prototype。 createUser@src/mongo/shell/db.js:1292:15 @(shell):1:1
    • 同样的错误:错误:管理员未授权执行命令 { grantRolesToUser: "admin", roles: [ "readWrite" ], writeConcern: { w: "majority", wtimeout: 600000.0 } } : _getErrorWithCode@src/mongo/shell/utils.js:25:13 DB.prototype.grantRolesToUser@src/mongo/shell/db.js:1493:19 @(shell):1:1
    • 没有没有用。我从mongod --auth 开始。仍然给了我同样的错误。我必须删除所有内容并重新安装所有内容,现在它可以工作了
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-25
    • 1970-01-01
    • 2020-02-02
    • 2019-05-30
    • 2015-10-30
    相关资源
    最近更新 更多