gpt4 book ai didi

mongodb - 更新角色用户 : not authorized on admin to execute command

转载 作者:可可西里 更新时间:2023-11-01 09:11:22 26 4
gpt4 key购买 nike

当我尝试获取有关副本的信息时,出现以下错误:

rep0:PRIMARY> rs.printReplicationInfo()
2015-05-19T13:30:29.231+0200 error: {
"$err" : "not authorized for query on local.system.namespaces",
"code" : 13
} at src/mongo/shell/query.js:131

我尝试用以下两个用户执行命令:

    [
{
"_id" : "admin.siteRootAdmin",
"user" : "siteRootAdmin",
"db" : "admin",
"roles" : [
{
"role" : "root",
"db" : "admin"
}
]
},
{
"_id" : "admin.mongoadmin",
"user" : "mongoadmin",
"db" : "admin",
"roles" : [
{
"role" : "userAdminAnyDatabase",
"db" : "admin"
},
{
"role" : "dbOwner",
"db" : "admin"
},
{
"role" : "clusterAdmin",
"db" : "admin"
}
]
}
]

虽然我有 clusterAdmin 角色来处理副本,但我尝试更新 mongoadmin 的角色以读取本地数据库(因为所有角色都在 admin db 上授予)但我收到以下错误:

rep0:PRIMARY> db.system.users.update({"user":"mongoadmin"},{$addToSet:{"roles":"readAnyDatabase"}})
WriteResult({
"writeError" : {
"code" : 13,
"errmsg" : "not authorized on admin to execute command { update: \"system.users\", updates: [ { q: { user: \"mongoadmin\" }, u: { $addToSet: { roles: \"readAnyDatabase\" } }, multi: false, upsert: false } ], ordered: true }"
}
})
  • 我需要什么才能完全访问所有除了 clusterAdmin 角色之外的副本命令?
  • 如果两个用户中的任何一个都拥有 admin db 的权限(mongoadmin 是 dbOwner),为什么我没有更新命令的权限?

最佳答案

我用错误的命令更新角色,这里是正确的命令:

db.grantRolesToUser( "mongoadmin", [{ role: "read", db: "local"}])

现在我可以检查副本信息了:

rep0:PRIMARY> rs.printReplicationInfo()
configured oplog size: 990MB
log length start to end: 617347secs (171.49hrs)
oplog first event time: Thu May 14 2015 14:25:04 GMT+0200 (CEST)
oplog last event time: Thu May 21 2015 17:54:11 GMT+0200 (CEST)
now: Thu May 21 2015 17:54:24 GMT+0200 (CEST)

关于mongodb - 更新角色用户 : not authorized on admin to execute command,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30324901/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com