gpt4 book ai didi

MongoDB : applyOps: not authorized on admin to execute command

转载 作者:行者123 更新时间:2023-12-05 04:01:35 34 4
gpt4 key购买 nike

美好的一天,

我在下面的 mongodb 中拥有 super 用户权限的用户(我使用 show users 命令确认了角色设置)

{
"_id" : "admin.mongoadmin",
"user" : "mongoadmin",
"db" : "admin",
"roles" : [
{
"role" : "readWrite",
"db" : "admin"
},
{
"role" : "root",
"db" : "admin"
}
],
"mechanisms" : [
"SCRAM-SHA-1",
"SCRAM-SHA-256"
]
}

当我尝试使用 mongorestore 恢复 oplog 时,出现错误:

失败:恢复错误:应用 oplog 时出错:applyOps:管理员未授权执行命令 { applyOps:[ { ts:时间戳(1552828309,1),h:4632811839329880092,v:2, op: "c", ns: "admin.$cmd", o: { create: "system.keys", idIndex: { v: 2, key: { _id: 1 }, name: "id", ns: "admin.system.keys"} }, o2: {} } ], $db: "admin"

mongorestore -u admin -p password --authenticationDatabase=admin --oplogFile 0000000000_0_oplog.bson  --oplogReplay --oplogLimit=1552828432 --dir='/oplog/temp'
2019-03-17T13:47:36.945+0000 preparing collections to restore from
2019-03-17T13:47:36.945+0000 replaying oplog
2019-03-17T13:47:36.962+0000 Failed: restore error: error applying oplog: applyOps: not authorized on admin to execute command { applyOps: [ { ts: Timestamp(1552828309, 1), h: 4632811839329880092, v: 2, op: "c", ns: "admin.$cmd", o: { create: "system.keys", idIndex: { v: 2, key: { _id: 1 }, name: "_id_", ns: "admin.system.keys" } }, o2: {} } ], $db: "admin" }

注意:我使用从 bsondump 获得的最后一个值指定了 oploglimit (--oplogLimit=1552828432)这个对吗?或者我错过了什么吗?

(即)

{"ts":{"$timestamp":{"t":1552828432,"i":79}},"t":{"$numberLong":"1"},"h":{"$numberLong":"-2072015676601300967"},"v":2,"op":"i","ns":"inventory.hari","ui":{"$binary":"avdlGH8AS1eBPXRytlO1Yg==","$type":"04"},"wall":{"$date":"2019-03-17T13:13:52.139Z"},"o":{"_id":"79","name":"Hari","role":"Developer","isEmployee":true}}
{"ts":{"$timestamp":{"t":1552828432,"i":80}},"t":{"$numberLong":"1"},"h":{"$numberLong":"-6279494628130059002"},"v":2,"op":"u","ns":"inventory.hari","ui":{"$binary":"avdlGH8AS1eBPXRytlO1Yg==","$type":"04"},"o2":{"_id":"79"},"wall":{"$date":"2019-03-17T13:13:52.139Z"},"o":{"_id":"79","name":"WD_Userjava.util.Random@9a7504c","role":"Developer","isEmployee":true}}

任何帮助表示赞赏。提前致谢。

最佳答案

use admin

db.createRole(
{
role: "interalUseOnlyOplogRestore",
privileges: [
{ resource: { anyResource: true }, actions: [ "anyAction" ] }
],
roles: []
}
)

db.createUser({
user: "root",
pwd: "password",
roles: [
{role: "root", db: "admin"},"__system","interalUseOnlyOplogRestore","backup"
]
})

最好将特权减少到如下所示。

db.createUser({
user: "root2",
pwd: "password",
roles: [
"interalUseOnlyOplogRestore"
]
})

之后你可以运行恢复命令

mongorestore --port 27017 --oplogReplay oplogRestore --authenticationDatabase admin -u root2 -p password

关于MongoDB : applyOps: not authorized on admin to execute command,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55208028/

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