0

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])
ducktyped
  • 4,354
  • 4
  • 26
  • 38

2 Answers2

2

Its something like that:

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

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/

Jeff_Alieffson
  • 2,672
  • 29
  • 34