代码改变世界

MongoDB not authorized on admin to execute command { replSetGetStatus: 1.0 }

2022-04-24 16:40  abce  阅读(1152)  评论(0编辑  收藏  举报
abce:PRIMARY> rs.status()
{
        "ok" : 0,
        "errmsg" : "not authorized on admin to execute command { replSetGetStatus: 3.0, lsid: { id: UUID(\"4f94da6c-3037-4737-a6c4-3b63b3d373e4\") }, $clusterTime: { clusterTime: Timestamp(3670799634, 3), signature: { hash: BinData(0, 6A33A3707C34740330740A97E639347377330CCE), keyId: 7040074646440947376 } }, $db: \"admin\" }",
        "code" : 33,
        "codeName" : "Unauthorized",
        "$clusterTime" : {
                "clusterTime" : Timestamp(3670799774, 3),
                "signature" : {
                        "hash" : BinData(0,"6Hvn3zVdNumgWz0nWRm/34rLAms="),
                        "keyId" : NumberLong("7040074646440947376")
                }
        },
        "operationTime" : Timestamp(3670799774, 3)
}

 

最初创建的用户权限是:

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

  

解决方案:
授权管理集群的权限即可

abce:PRIMARY> use admin
switched to db admin
abce:PRIMARY>  db.grantRolesToUser("m_admin", ["clusterAdmin"])