How to create standard user in MongoDB on ubuntu 20.04 LTS - TechBeginner

Welcome to TechBeginner.in, Tech Beginner provides technical blog for Online Linux Tutorials, Ubuntu Tutorials, Redhat Tutorials and CentOS 7, Configuration of server like Web Server, Application server, Database server, Window server, networking, html, css, java script, php, wordpress, opencart, magento, joomla and etc.

How to create standard user in MongoDB on ubuntu 20.04 LTS

Share This


 

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.

 

No comments:

Post a Comment