0

How can I create a user and grant it read-only access for all databases available in MongoDB (2.2/2.4/2.6) instance?

I am new to MongoDB, please provide the detailed, step-by-step process.

Hannah Vernon
71.1k22 gold badges178 silver badges324 bronze badges
asked Jan 23, 2021 at 17:48
0

2 Answers 2

1

Upgrade to any one of recent MongoDB versions and then it's very easy follow the below steps:

  1. Enable authentication on the /etc/mongod.conf file
 security:
 authorization: enabled
  1. Create a read user on admin DB, since you want to access all DBs. If specific DB then create on that specific db
use admin 
 db.createUser( 
 {
 user: "read_admin",
 pwd: "yourpassword", 
 roles: [ { role: "readAnyDatabase", db: "admin" } ] 
 } )
  1. Restart the MongoDB service
sudo service mongod restart
  1. Login into the mongo shell and check the user
mongo -u read_admin --authenticationDatabase admin
answered Oct 19, 2021 at 11:24
0

Here are the steps to enable authorization, and create the user with the readAnyDatabase access for the MongoDB v2.4 deployment.

As an example, you can try the following tutorial from MongoDB v4.2 documentation. This tutorial Enable Access Control steps are the similar to that of the version 2.4 you want to work with. Note that, some commands, like createUser is addUserin v2.4, have different syntax - please be mindful of that.

answered Jan 25, 2021 at 14:07

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.