Creating users in MongoDB
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