Wednesday, 12 November 2014

create a new user of MongoDB


E.g. you want to create a new user of you local MongoDB.

you should first connect to it by shell

mongo localhost:<port>/<dbname> -u <dbuser> -p <dbpassword>

then run:

use <dbname>

then run:

db.createUser(
    {
      user: "test",
      pwd: "test",
      roles: [
          "readWrite"
      ]
    }
)

that create a user "test" and password is "test". this user can read and write.

You cannot trust Robomongo for user management, because database users management are data, but is special.



to delete a user:


db.dropUser("test")




No comments:

Post a comment