Creating users in MongoDB

Creating users in MongoDB is as simple as running the following commands:

use db_name;
user: "user_name",
pwd: "password",
roles: [ "readWrite", "dbAdmin" ]


  • 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