Categories
MongoDB Open Source Solutions Web

Creating users in MongoDB

[adinserter block=”2″]
Creating users in MongoDB is as simple as running the following commands:

use db_name;
db.createUser({
user: "user_name",
pwd: "password",
roles: [ "readWrite", "dbAdmin" ]
})

Here:

  • db_name : Database Name
  • user_name: Username of the user
  • password: Password of the user
  • roles: Roles of the user – Is an array and can be empty
    • Eg. readWrite, dbAdmin, clusterAdmin, readAnyDatabase

Leave a Reply

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