用户角色在mongo中运行replSetGetStatus命令

时间:2018-06-13 07:48:11

标签: mongodb mongodb-query

我正在尝试运行以下命令来获取我的副本集状态。但我得到了以下错误:

db.adminCommand({replSetGetStatus: 1})
{
    "ok" : 0,
    "errmsg" : "not authorized on admin to execute command { replSetGetStatus: 1.0 }",
    "code" : 13
}

这是db.system.users集合中的用户文档

{
    "_id" : "admin.prodDb",
    "user" : "prodDb",
    "db" : "admin",
    "credentials" : {
        "SCRAM-SHA-1" : {
            "iterationCount" : 10000,
            "salt" : "okdfd74YA3/mTiSad2+zjS4Ag==",
            "storedKey" : "aoCDvsdfh+asvbGajSinnUvXaqc08=",
            "serverKey" : "kdc6B3LgvrNE4gT1CsBEzEvDCadms="
        }
    },
    "roles" : [
        {
            "role" : "readWrite",
            "db" : "XXXX"
        },
        {
            "role" : "readWrite",
            "db" : "XXXX"
        },
        {
            "role" : "readWrite",
            "db" : "XXXX"
        },
        {
            "role" : "readWrite",
            "db" : "XXXX"
        }
    ]
}

然后我尝试通过执行此操作来提供对admin db的读访问权限 -

db.system.users.update({'user': 'prodDb'}, {$push: {"roles": {"role": "read", "db": "admin"}}})

我还将角色从read更改为readWrite,但同样的问题仍然存在。我不想向此用户提供admin权限。我该怎么办。

1 个答案:

答案 0 :(得分:1)