This post discussed how to create a read-only role in the MongoDB database. Without further ado, let's start.
Imagine you're a DevOps engineer or the team leader for the Backend team, normally these roles are the role who responsible to grant the access into the database.
There are two newly hired developers who just joined your team and the management decided to provide a read-access only to the database in the staging environment in order to ease the debugging workflow. Lets's call them Developer A and Developer B.
Here are the list of Mongo databases that is available.

Firstly, we would have to create a user for access the DB. Although you could create a user in any database. But I recommend to create all user at admin database so it is easier to manage. So in future, you hired a DB Administrator and you could just grant him an access to the admin database so he could help you manage the DB user role creation without exposing any other database.
In this tutorial, we will using Mongo Shell to create user.
use admin; // Make sure we go to the admin database
// Create devA user and read access only to client DB.
db.createUser({
user: "devA",
pwd: "devA",
roles: [
{ role: "read", db: "client" },
]
});
Using the simple above command we will now have a devA user who has only read-access to the client database and you can see the user successfully added in the below screenshot.