- Reference >
- Database Commands >
- Role Management Commands >
- updateRole
updateRole¶
On this page
Definition¶
-
updateRole¶ Updates a user-defined role. The
updateRolecommand must run on the role’s database.An update to a field completely replaces the previous field’s values. To grant or remove roles or privileges without replacing all values, use one or more of the following commands:
Warning
An update to the
privilegesorrolesarray completely replaces the previous array’s values.The
updateRolecommand uses the following syntax. To update a role, you must provide theprivilegesarray,rolesarray, or both:The
updateRolecommand has the following fields:Field Type Description updateRolestring The name of the user-defined role role to update. privilegesarray Optional. Required if you do not specify rolesarray. The privileges to grant the role. An update to theprivilegesarray overrides the previous array’s values. For the syntax for specifying a privilege, see theprivilegesarray.rolesarray Optional. Required if you do not specify privilegesarray. The roles from which this role inherits privileges. An update to therolesarray overrides the previous array’s values.writeConcerndocument Optional. The level of write concern for the update operation. The writeConcerndocument takes the same fields as thegetLastErrorcommand.In the
rolesfield, you can specify both built-in roles and user-defined role.To specify a role that exists in the same database where
updateRoleruns, you can either specify the role with the name of the role:Or you can specify the role with a document, as in:
To specify a role that exists in a different database, specify the role with a document.
Behavior¶
A role’s privileges apply to the database where the role is created. The
role can inherit privileges from other roles in its database. A role
created on the admin database can include privileges that apply to all
databases or to the cluster and can inherit
privileges from roles in other databases.
Required Access¶
You must have the revokeRole action on all databases in order to update a role.
You must have the grantRole action on the database of each role in the roles array
to update the array.
You must have the grantRole action on the database of each
privilege in the privileges array to update the array. If a privilege’s
resource spans databases, you must have grantRole on the
admin database. A privilege spans databases if the privilege is any of
the following:
- a collection in all databases
- all collections and all database
- the
clusterresource
Example¶
The following is an example of the updateRole command that
updates the myClusterwideAdmin role on the admin database.
While the privileges and the
roles arrays are both optional, at least
one of the two is required:
To view a role’s privileges, use the rolesInfo command.