您的位置:首页 > 数据库 > Mongodb

[MongoDB] not authorized on test to execute command-MongoDB的权限配置

2016-06-14 16:22 651 查看



not authorized on test to execute command-MongoDB的权限配置

直接报Command '$eval' failed: not authorized on这个错误,可以确认是权限的问题

解决方案:

在官网  http://docs.mongodb.org/manual/reference/command/eval/#dbcmd.eval 有一段描述:

If authorization is enabled, you must have access to all actions on all resources in order to run eval. Providing such access is not recommended, but if your organization requires a user to run eval, create a role that grants anyAction on anyResource. Do not
assign this role to any other user.

解决步骤:

1)不带--auth参数启动数据库,所以不需要帐号即可连上MongoDB。

2)新建一个角色,比如叫 sysadmin,需要先切换到admin库进行如下操作:

[C#] 纯文本查看 复制代码

?
3)然后,新建一个用户,使用这个角色,注意,这个角色的db是admin,操作如下:

[C#] 纯文本查看 复制代码

?
好了现在重启启动数据库带上

--auth

就可以正常执行了
转载自:http://www.sufeinet.com/thread-11978-1-1.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: