Add user and database in mongodb

To create database and user and grant readwrite access you can use following:

$ mongo
 > use admin
 > db.auth("admin", "password")
 > use database
 > db.createUser(
   {
     user: "user",
     pwd: "userpassword",
     roles: [ "readWrite", "database" ]
   }
 )

Leave a Reply

Your email address will not be published. Required fields are marked *