- Reference >
mongoShell Methods >- User Management Methods >
- db.revokeRolesFromUser()
db.revokeRolesFromUser()¶
On this page
Definition¶
-
db.revokeRolesFromUser()¶ Removes a one or more roles from a user on the current database. The
db.revokeRolesFromUser()method uses the following syntax:The
revokeRolesFromUsermethod takes the following arguments:Parameter Type Description userstring The name of the user from whom to revoke roles. rolesarray The roles to remove from the user. writeConcerndocument Optional. The level of write concern for the modification. 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
db.revokeRolesFromUser()runs, 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.
The
db.revokeRolesFromUser()method wraps therevokeRolesFromUsercommand.
Behavior¶
Replica set¶
If run on a replica set, db.revokeRolesFromUser() is executed using majority write concern by default.
Required Access¶
You must have the revokeRole action on a database to revoke a role on that database.
Example¶
The accountUser01 user in the products database has the following
roles:
The following db.revokeRolesFromUser() method removes the two of
the user’s roles: the read role on the stock database and
the readWrite role on the products database, which is also
the database on which the method runs:
The user accountUser01 user in the products database now has only
one remaining role: