MongoDB报错"not authorized on root to execute command"问题解决一例


用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 }

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/15498/viewspace-2145516/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/15498/viewspace-2145516/

你可能感兴趣的:(MongoDB报错"not authorized on root to execute command"问题解决一例)