db.addUser({ user: "Carlos",
pwd: "pwd",
customData: { employeeId: 12345 },
roles: [
{ role: "clusterAdmin", db: "admin" },
{ role: "readAnyDatabase", db: "admin" },
"readWrite"
]
})
这是 mongo wiki http://docs.mongodb.org/manual/reference/method/db.addUser/ 中的示例设置脚本
这个脚本有什么问题...
我正进入(状态
{
"user" : "Carlos",
"pwd" : "ccb9d76967dcb0315ab62e88cb5c372b",
"customData" : {
"employeeId" : 12345
},
"roles" : [
{
"role" : "clusterAdmin",
"db" : "admin"
},
{
"role" : "readAnyDatabase",
"db" : "admin"
},
"readWrite"
],
"_id" : ObjectId("5444963f3507d43d2138fa6f")
}
未捕获异常:无法添加用户:角色必须是非空字符串。
最佳答案
这适用于 Mongo 2.4.5
db.addUser({ user: "dbOwner", pwd: "dbOwner", roles: [ "dbOwner", "DBNAME" ]})
关于mongodb 用户认证,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26458841/