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

其他资讯

售后响应及时

7×24小时客服热线

数据备份

更安全、更高效、更稳定

价格公道精准

项目经理精准报价不弄虚作假

合作无风险

重合同讲信誉,无效全额退款