Create readonly user for all databases

How to create a user and grant him read-only access for all databases available in mongodb(2.2/2.4/2.6) instance. I am new to mongodb, please provide detail step by step process.

user name: sec.ai
password: test
databases: school, local, admin, employee, deptt

Hi @Amanullah_Ashraf1,

Welcome to MongoDB community.

Please note that MongoDB versions 2.2 - 2.6 is not supported for a long time.

In modern MongoDB versions you need to use a built-in role readAnyDatabase for this:

https://docs.mongodb.com/manual/reference/built-in-roles/#readAnyDatabase

Thanks
Pavel

1 Like

More about the currently supported MongoDB versions here.

At the time I’m writing this, MongoDB 3.6, 4.0, 4.2 and 4.4 are supported. Note that MongoDB 3.6 will reach its end of life in April 2021. So it’s time to update :smiley:.

Cheers,
Maxime.

1 Like

Can I use ’ readAnyDatabase ’ for older version of Mongo DB like 1.8, 2.2, 2.4, 2.6

@Amanullah_Ashraf1,

Looking at 2.6 docs it does:
https://docs.mongodb.com/v2.6/reference/built-in-roles/#readAnyDatabase

Check for others as well.

But you shouldn’t use a 6+ year old versions.

Thanks
Pavel

1 Like

Wow 1.8!
Released in 2011 and EOL in September 2012. It’s really time to do something here.

1 Like