not authorized on test to execute command { $eval: \"return 1111\"

一:问题描述


> db.eval( 'TestConcat("abc","123")' );
2015-03-04T15:18:54.062+0800 {
     "ok" : 0,
     "errmsg" : "not authorized on test to execute command { $eval: \"return 1111\" }" ,
     "code" : 13
} at src/mongo/shell/db.js:403
>

二:出错原因


权限不够


三:解决办法


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

 

> use admin
switched to db admin
> db.createRole({role: 'sysadmin' ,roles:[],
privileges :[
{resource:{anyResource: true },actions:[ 'anyAction' ]}
]})


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

  

> use woplus
switched to db woplus
> db.createUser({
user : 'woplus' ,
pwd: 'wo@1990' ,
roles:[
{role: 'sysadmin' ,db: 'admin' }
]})


--本篇文章主要参考自: http://www.2cto.com/database/201503/380332.html


你可能感兴趣的:(not authorized on test to execute command { $eval: \"return 1111\")