How to create standard user in MongoDB on ubuntu 20.04 LTS


 

MongoDB utilizes Role-Based Access Control (RBAC) to administer admittance to a MongoDB framework. A client is allowed at least one jobs that decide the client’s admittance to information base assets and tasks. Outside of job tasks, the client has no admittance to the framework.

 

In this post, We will create a standard user in MongoDB on ubuntu 20.04 LTS

 

Step 1: Get MongoDB Shell

 

You need to get access of your MongoDB Shell with root privileges by using the given command.

mongo -u root -p password localhost/admin

If you do not enable auth, So then you need to execute the below command.

mongo

 

Step 2: Choose or Select the Database

 

After getting shell access, You need to create MongoDB database and create standard user for the same database like this.

use database_name_here


 

Step 3: Create Standard User 

 

We are ready to create a standard user, Which is use in make connection from any server side programing language like PHP, Javam Python and more.

 

This user have readWrite permission on the chosen database.

 

db.runCommand({"createUser" : "username_here","pwd" : "password_here","customData" : {},"roles" : [{"role" : "readWrite","db" : "database_name_here"}]}); 


 

Step 4: Get Verify the User 

 

After creation of the user, You can verify it by following command.

use database_name_here
db.getUsers()

You should get output like this.

 

Step 5: Delete the User 

 

If you want to delete or remove any user from the MongoDB So then you need to execute the following command.

use database_name_here
db.dropUser("username") 

 

Conclusion

 

We have successfully created standard user with MongoDB on ubuntu machine, Still you have any issue leave a comment.

 

How to create standard user in MongoDB on ubuntu 20.04 LTS

Leave a Reply

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

Scroll to top