Articles → MONGODB → Create A User In Mongodb
Create A User In Mongodb
Steps Of Creating A User
- Switch to the database
- Use the createUser method for creating the user
Syntax
db.createUser({user:<username>, pwd:<password>, roles:[<roles>]})
Create A User
use admin
db.createUser({user:"gyan", pwd:"gyan", roles:["userAdminAnyDatabase"]})
How To Authenticate Credentials?
db.auth([user_name], [password])