有没有办法从 Moped 将用户添加到数据库。我没有看到任何与 mongo 控制台等效的命令
db.addUser(user, pass, [roles])
它是这样的:
db.collection.insert( { user: "username", password: 'password', roles: ['role1','role2'] )
从 MongoDB 3.0 开始,你必须使用 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 管理员,请使用以下命令:
db.createUser({ user: "admin", pwd: "adminpwd", roles: [ "root" ]})
看这里: http ://docs.mongodb.org/manual/tutorial/add-user-to-database/