September 5, 2020

Create a Read Only MongoDB User

There are times when you need account read only access to a database.

To create a read only database user MongoDB, do the following steps:

  1. Login as a MongoDB administrator.
$ mongo -u admin -p --authenticationDatabase admin
  1. Show list of database on MongoDB.
>>> show dbs
  1. Select database.
>>> use edxapp
  1. Create a new user with permission read only on the database.
>>> db.createUser({user: "edxapp_read", pwd: "password", roles: [{role: "read", db: "edxapp"}]})
  1. Done.