Updated on 2023-10-08 GMT+08:00

User-Defined Roles

A user-defined role is a customized role created by a user by running a command. It contains only one or more CRUD operations or one or more built-in roles. You can customize roles based on different resources and actions. User-defined roles are applied in the same way as built-in roles.

Creating, Modifying, and Deleting Roles

  • Before creating a role, connect to the DB instance as a user with the required permission (for example, rwuser).
  • You can use createRole to create a user-defined role to control permissions for different databases and collections or inherit permissions from other roles.
  • After a role is created, you can run grantPrivilegesToRole, grantRolesToRole, revokeRolesFromRole, or revokePrivilegesFromRole to obtain or revoke permissions of the role. For details, see Creating and Managing Roles.