MongoDB报错"notauthorizedonroottoexecutecommand"问题解决一例
用root用户在修改MongoDB认证机制的时候报错:
>use admin
>db.auth('root','123456')
> var schema=db.system.version.findOne({"_id" : "authSchema"})
Y> schema.currentVersion = 3
3
> db.system.version.save(schema)
WriteResult({
"writeError" : {
"code" : 13,
"errmsg" : "not authorized on root to execute command { update: \"system.version\", updates: [ { q: { _id: \"authSchema\" }, u: { _id: \"authSchema\", currentVersion: 3 }, multi: false, upsert: true } ], ordered: true }"
}
})
此错误是因为没有授权给admin用户对system.version表执行命令的权限,解决方法如下:
> db.grantRolesToUser ( "root", [ { role: "__system", db: "admin" } ] )
再次执行命令成功:
> db.system.version.findOne({"_id" : "authSchema"})
{ "_id" : "authSchema", "currentVersion" : 3 }
网页题目:MongoDB报错"notauthorizedonroottoexecutecommand"问题解决一例
文章出自:
http://dzwzjz.com/article/gjichc.html