User Manager用户管理器
Posted on: 24/02/2020 (last updated: 13/08/2021) by Thomas Zahn
User Manager, along with the Role Manager, simplifies MongoDB user management tasks like creating users and granting roles. 用户管理器和角色管理器简化了MongoDB用户管理任务,如创建用户和授予角色。Try both features today今天就试试这两个功能.。
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创建MongoDB用户

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.要添加关于用户的可选信息,请使用自定义数据选项卡并将其插入JSON。Click on Validate JSON to ensure that the code is correct.单击“校验JSON”以确保代码正确。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.点击“更新用户”。
With Studio 3T 2018.4, it’s now possible to view the JSON code behind the user creation by clicking on Show Code.使用Studio 3T 2018.4,现在可以通过单击“显示代码”查看用户创建背后的JSON代码。
Delete a user删除用户
Select the user and click on Drop to delete the user from the list.选择用户并单击“删除”从列表中删除该用户。
Grant MongoDB roles to a user将MongoDB角色授予用户
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.您还可以单击顶部的组合框,从MongoDB实例的其他数据库中选择角色,以防您的新用户也访问其他数据库。
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
.dbOwner
和readWrite
来授予他们对数据库的读写访问权。
When done, click the “Grant” button.完成后,单击“授予”按钮。
Grant roles to multiple users at once一次向多个用户授予角色
In MongoDB, users are defined for specific databases. 在MongoDB中,用户是为特定数据库定义的。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:因此,毫不奇怪,MongoDB的API使得通过grantRolesToUser
方法为用户分配角色列表变得容易:
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.然而,MongoDB的角色API(http://docs.mongodb.org/v2.6/reference/method/js-role-management/)没有直接介绍另一种常见的用例,在这种用例中,您希望一次性将一个(可能是新创建的)角色或多个角色分配给用户列表。
With Studio 3T, you can grant roles to multiple users at once.使用Studio 3T,您可以同时向多个用户授予角色。
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. 假设您刚刚在数据库“test”上创建了一个新角色“rwAdmin”,该角色让用户在该数据库上创建dbadmin,并让他们对其进行读写。You now want to assign this new role and the existing role “userAdmin” to a group of users.现在,您需要将这个新角色和现有角色“userAdmin”分配给一组用户。
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服务器,选择定义用户的数据库,然后单击工具栏中的“用户”图标打开该数据库的“用户管理”选项卡。

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.您可以验证这两个角色是否确实被授予了所选用户组。

Once you’re done granting roles, read more about how to set up user authentication or read more about the complementary Role Manager feature.完成角色授予后,请阅读更多关于如何设置用户身份验证的信息,或阅读更多关于补充角色管理器功能的信息。