一、设置密码及用户角色【1】
> db.createUser(
... {
... user: "maxh",
... pwd: "123",
... roles: [ "readWrite", "dbAdmin" ]
... }
... )
Successfully added user: { "user" : "maxh", "roles" : [ "readWrite", "dbAdmin" ]
}
二、按照【2】创建,还是有
> db.createUser({user:"myUserAdmin",pwd:"zxc123",role:[{role:"userAdminAnyDatabase",db:"admin"}]})
2016-04-26T17:11:25.814+0800 E QUERY [thread1] Error: couldn't add user: "role" is not a valid argument to createUser :
_getErrorWithCode@src/mongo/shell/utils.js:23:13
DB.prototype.createUser@src/mongo/shell/db.js:1225:11
简直服了自己,这都能敲错了。
> db.createUser({user: "myUserAdmin", pwd:"zxc123",roles:[{role: "userAdminAnyDa
tabase",db:"admin"}]})
Successfully added user: {
"user" : "myUserAdmin",
"roles" : [
{
"role" : "userAdminAnyDatabase",
"db" : "admin"
}
]
}
似乎是没有密码和有密码没有什么大的差别啊,直接mongo进去以后show dbs,use db,show collections都不受限制的怎么回事,但是用db.auth("", "")登录也是正确的。
-------------- --
参考:https://docs.mongodb.org/manual/reference/method/db.createUser/
---------------2016-4-26 17:25:57--
【2】修改:mongodb创建授权用户