On Mongodb 2.6.4我想为特定数据库创建一个管理员用户。
我试过了:
use myapp-dev
db.createUser(
{
user: "myapp-dev-admin",
pwd: "xxx",
roles:
[
{
role: "userAdmin",
db: "myapp-dev"
}
]
}
)
它似乎创建了用户,我可以使用db.auth('myapp-dev-admin', 'xxxx')
除非他无法对数据库执行任何操作。
> show dbs
2014-10-30T02:11:51.376-0700 listDatabases failed:{
"ok" : 0,
"errmsg" : "not authorized on admin to execute command { listDatabases: 1.0 }",
"code" : 13
} at src/mongo/shell/mongo.js:47
> show collections
2014-10-30T02:12:02.672-0700 error: {
"$err" : "not authorized for query on myapp-dev.system.namespaces",
"code" : 13
} at src/mongo/shell/query.js:131
答案 0 :(得分:0)
用这个来修正......
use mydb
db.createUser({user: 'mydbadmin', pwd: 'xxx', roles: ["dbOwner"]})
答案 1 :(得分:0)
这对我有用,希望它有帮助...
db.createUser({
"user": "username",
"pwd": passwordPrompt(),
"roles": [
"readWrite",
"dbAdmin"
]
})