Try Studio 3T for Free

User Manager

User Manager, along with the Role Manager, simplifies MongoDB user management tasks like creating users and granting roles. Try both features today.

Basics

To open User Manager:

Grant roles to users by clicking the 'Users' button in the Global Toolbar

  • Button – Click on Users in the global toolbar
  • Right-click – Right-click on any target database in the Connection Tree and choose Manage Users

Create MongoDB user

  1. Open User Manager and click on Add.
  2. Enter the username.
  3. Enter the password. This is a required field.
  4. Grant the relevant roles by clicking on Grant Roles. They will populate the table under the Roles tab. Alternatively, remove a role by selecting it and clicking on Revoke Roles. Need to create a new role? Follow these steps.
  5. To add optional information about the user, use the Custom Data tab and insert it in JSON.
  6. Click on Validate JSON to ensure that the code is correct.
  7. Click on Add User.

Edit a user

  1. Open User Manager and select the user.
  2. Click on Edit to open the user profile and make changes as needed.
  3. Click on Update User.

Edit the User by selecting the user and clicking 'Edit'

With Studio 3T 2018.4, it’s now possible to view the JSON code behind the user creation by clicking on Show Code.

Delete a user

Select the user and click on Drop to delete the user from the list.

Edit Users by selecting the user and clicking 'Drop'

Grant MongoDB roles to a user

Choose the user and click on Grant Roles.

Manage MongoDB Roles and Users

Find the role by entering it in the text or choosing it from the list. Built-in roles will be marked by a yellow icon, custom roles by a green icon.

You can also click the combo-box at the top to choose from roles in other databases of your MongoDB instance, in case you want your new user to access other databases as well.

For our example, we will simply make our new user an administrator of their database and also grant them read-write access to it by selecting the roles dbOwner and readWrite.

When done, click the “Grant” button.

Grant roles to multiple users at once

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 (http://docs.mongodb.org/v2.6/reference/method/js-role-management/) 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.

With Studio 3T, you can grant roles to multiple users at once.

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.

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.Grant roles to users by clicking the 'Users' button in the Global Toolbar

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.Select the users you want to give roles to

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

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

Once you’re done granting roles, read more about how to set up user authentication or read more about the complementary Role Manager feature.

Updated on February 24, 2020

Was this article helpful?

Related Articles