In MongoDB, users are defined for specific databases. Each user is then assigned a list of roles that in turn define the user’s privileges.

Not surprisingly, MongoDB’s API therefore makes it easy to assign a user a list of roles via the grantRolesToUser method:

db.grantRolesToUser( "<username>", [ <roles> ], { <writeConcern> } )

However, MongoDB’s role API ( doesn’t directly cover another common use case where you want to assign a (maybe newly created) role or multiple roles to a list of users in one go.

Studio 3T (formerly MongoChef) makes it very easy to assign roles to multiple MongoDB users at once.

Download Studio 3T
Get Download Link for Later

Let’s consider the following example. Say you have just created a new role “rwAdmin” on database “test” that makes users dbAdmins on that database and also let’s them read from and write to it. You now want to assign this new role and the existing role “userAdmin” to a group of users.

1) Connect to your MongoDB server as a user that has sufficient privileges to grant roles to users, select the database where your users are defined, and click the “Users” icon in the toolbar to open the user management tab for that database.

MongoDB GUI Manage MongoDB Users

2) You will now see a list of all your users in the selected database. Simply select all users that you want to grant those roles to and click the “Grant Roles…” button.

Grant Roles to MongoDB Users

3) Now, select from the list of available roles those that you want to grant to your list of selected users, and click “Grant”.

Manage MongoDB Roles with a GUI

4) Et voilà 🙂  You can verify that those two roles were indeed granted to the group of selected users.

View MongoDB Users and Roles with a GUI

Download Studio 3T and be on your way to super-easy MongoDB user management. Once you’re done granting roles, read more about how to set up user authentication, how to find users that have been granted specific MongoDB roles, among other helpful tips.

Try Studio 3T
Get Download Link for Later

Editor’s Note: This post was originally published in January 2015.