rubymongodbmoped

Moped: How to adduser to a mongo database


Is there a way to add user to a database from Moped. I dont see any equivalent command to mongo console

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

Solution

  • Starting from MongoDB 3.0 U have to use createUser, not addUser. The syntax is:

    db.createUser(
        {
          user: "username",
          pwd: "12345678",
          roles: [
             { role: "read", db: "reporting" },
             { role: "read", db: "products" },
             { role: "read", db: "sales" },
             { role: "readWrite", db: "accounts" }
          ]
        }
    )
    

    To add root admin use the following:

    db.createUser({ user: "admin", pwd: "adminpwd", roles: [ "root" ]})
    

    look at here: http://docs.mongodb.org/manual/tutorial/add-user-to-database/