在 mongo 2.4.x 中,它支持在 admin 数据库中创建用户的新方法,我认为使用userAdminAnyDatabase角色创建的用户应该能够访问所有其他数据库,对吧?
db.addUser({user:"u", pwd:"p", roles:["userAdminAnyDatabase"]})
但是,它不能按照文档执行此操作。
当我以 2.2.x 样式创建用户时,它可以工作。
db.addUser("u","p")
我的问题是我误操作了吗?如果我想创建一个可以使用 2.4.x 语法访问所有数据库的用户,那么正确的方法是什么?还需要其他选项吗?
谢谢。
这是详细的shell代码:
➜ mgo ✗ mongo
MongoDB shell version: 2.4.5
connecting to: test
> use admin
switched to db admin
> db.addUser({user: "u", pwd: "p", roles:["userAdminAnyDatabase"]})
{
"user" : "u",
"pwd" : "d4198ee555320fa5c048da6d6da440d8",
"roles" : [
"userAdminAnyDatabase"
],
"_id" : ObjectId("51dc20f0282f72950455b62e")
}
> db.auth(
Display all 170 possibilities? (y or n)
> db.auth("u","p")
1
> ^C
bye
➜ mgo ✗ mongo admin -u u -p p
MongoDB shell version: 2.4.5
connecting to: admin
> show dbs
Tue Jul 9 22:44:47.959 JavaScript execution failed: listDatabases failed:{ "ok" : 0, "errmsg" : "unauthorized" } at src/mongo/shell/mongo.js:L46
> use admin
switched to db admin
> db.addUser("uncle", "peter")
{
"user" : "uncle",
"readOnly" : false,
"pwd" : "e42842e07c4fc324e9724d6aa41f6411",
"_id" : ObjectId("51dc22456642fa58413adffc")
}
> db.auth("uncle", "peter")
1
> ^C
bye
➜ mgo ✗ mongo admin -u uncle -p peter
MongoDB shell version: 2.4.5
connecting to: admin
> show dbs
admi (empty)
admin 0.203125GB
local 0.078125GB
qortex_global 0.203125GB
qortexprod 0.203125GB
test (empty)
>