【问题标题】:Moped: How to adduser to a mongo database助力车:如何将用户添加到 mongo 数据库
【发布时间】:2014-02-22 14:59:51
【问题描述】:

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

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

【问题讨论】:

    标签: ruby mongodb moped


    【解决方案1】:

    是这样的:

    db.collection.insert( { user: "username", password: 'password', roles: ['role1','role2'] )
    

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-01-09
        • 1970-01-01
        • 2023-03-20
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多