有没有办法从Moped添加用户到数据库。我没有看到mongo console
的任何等效命令db.addUser(user, pass, [roles])
答案 0 :(得分:2)
类似的东西:
db.collection.insert( { user: "username", password: 'password', roles: ['role1','role2'] )
答案 1 :(得分:0)
从MongoDB 3.0开始,U必须使用createUser,而不是addUser。 语法是:
db.createUser(
{
user: "username",
pwd: "12345678",
roles: [
{ role: "read", db: "reporting" },
{ role: "read", db: "products" },
{ role: "read", db: "sales" },
{ role: "readWrite", db: "accounts" }
]
}
)
要添加root admin,请使用以下命令:
db.createUser({ user: "admin", pwd: "adminpwd", roles: [ "root" ]})
看这里: http://docs.mongodb.org/manual/tutorial/add-user-to-database/