成都创新互联网站制作重庆分公司

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://cxhlcq.com/article/gjichc.html

其他资讯

在线咨询

微信咨询

电话咨询

028-86922220(工作日)

18980820575(7×24)

提交需求

返回顶部