0

有没有办法从 Moped 将用户添加到数据库。我没有看到任何与 mongo 控制台等效的命令

db.addUser(user, pass, [roles])
4

2 回答 2

2

它是这样的:

db.collection.insert( { user: "username", password: 'password', roles: ['role1','role2'] )
于 2014-02-22T18:36:54.763 回答
0

从 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/

于 2015-04-28T05:17:34.787 回答