Basics
To open User Manager:
- 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
- Open User Manager and click on Add.
- Enter the username.
- Enter the password. This is a required field.
- 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.
- To add optional information about the user, use the Custom Data tab and insert it in JSON.
- Click on Validate JSON to ensure that the code is correct.
- Click on Add User.
Edit a user
- Open User Manager and select the user.
- Click on Edit to open the user profile and make changes as needed.
- Click on Update User.
Delete a user
Select the user and click on Drop to delete the user from the list.
Grant MongoDB roles to a user
Choose the user and click on Grant Roles.
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.
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.
Now, select from the list of available roles those that you want to grant to your list of selected users, and click “Grant”.
Et voilà 🙂 You can verify that those two roles were indeed granted to the group of selected users.