报错信息:
> use admin
switched to db admin
> db.createUser({user:"hz", pwd:"hz", roles:[{role:"userAdminAnyDatabase",db:"ad
min"}]})
2016-04-19T18:31:42.712+0800 E QUERY [thread1] Error: couldn't add user: not
authorized on admin to execute command { createUser: "hz", pwd: "xxx", roles: [
{ role: "userAdminAnyDatabase", db: "admin" } ], digestPassword: false, writeCon
cern: { w: "majority", wtimeout: 30000.0 } } :
_getErrorWithCode@src/mongo/shell/utils.js:23:13
DB.prototype.createUser@src/mongo/shell/db.js:1230:11
@(shell):1:1
解决办法:
创建admin的超级权限: mongo
use admin; db.addUser('root','sa') 增加了root帐号,这个时候执行show collections;提示没有权限,必须先执行db.auth('root','sa') ,返回1说明验证成功!返回0说明验证失败! 直接登陆其他表时,必须先use admin;db.auth('root','sa'),再执行use keke;show collections;否则还是没有权限。