How to create user in MongoDB with read only privilege

Search
Generic filters
Exact matches only
Filter by Custom Post Type

We can create user in MongoDB with read-only privilege with few quick steps. During user creation, read-only role on a database will be assigned to the user.

 

Steps

 

Connect to MongoDB as the admin user

Create the user in MongoDB and assign read-only privilege to the user

Authenticate to MongoDB as the new user and test the read-only privilege

 

 

Connect to MongoDB as the admin user.

 

The admin user, being the privileged user should authenticate on “admin” database. Follow the below steps to connect to MongoDB as the admin user

$ mongo$ use adminMongoDB Enterprise > db.auth("admin","wysheid")   # provide admin user and password

Create user in MongoDB and assign read-only privilege to the user.

 

Make sure that you are in the admin database before executing this command

MongoDB Enterprise > db.createUser({user: "user1",pwd: "test", roles: [{role:"read", db: "school"}]})

In above exampe, 
    use1==> username ,
    pwd==> password
    read==> read only role 
    db/school ==> name of the database

 

Authenticate to MongoDB as the new user and test the read-only privilege.

 

This read-only user  should authenticate on the admin database before  using the school database

$ mongo
execute the beloe command from MongDB Shell 

 MongoDB Enterprise > use admin MongoDB Enterprise > db.auth("user1","test") MongoDB Enterprise > use school MongoDB Enterprise > show collections MongoDB Enterprise > db.class.find()  ==> this command will select the documents or records from class collection

 

Video Demonstration

Here  is the complete video tutorial

 

Hope this helps 🙂

 

Thanks

Wysheid Team

Liked this Article.?

We have lot more interesting posts like this!  Join more than 5000 subscribers who stays ahead on technology.

By entering your email, you agree to the Terms and Conditions and Privacy Policy and cookies usage

You Make like the below posts

About The Author

Share on

Share on facebook
Share on google
Share on twitter
Share on linkedin
Share on pinterest

Leave a comment

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

Can't Find What You Are Looking For?.

Please enter the details below. We will try our best for you :-)

We have more amazing posts

Try searching here

lick edit button to change this text. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper mattis, pulvinar dapibus leo.

We assure our best to meet up to your expectations

Your Feedback will help us

Glad That You Liked It

Your Feedback will help us to improve