Articles → MONGODB → Create A User In Mongodb

Create A User In Mongodb






Steps Of Creating A User




  1. Switch to the database
  2. 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"]})


Picture showing creating a user in mongodb



How To Authenticate Credentials?




db.auth([user_name], [password])


Picture showing login to the database using auth method in mongodb



Posted By  -  Karan Gupta
 
Posted On  -  Friday, June 14, 2024

Query/Feedback


Your Email Id
 
Subject
 
Query/FeedbackCharacters remaining 250