Docs Home → Develop Applications → MongoDB Manual
db.dropAllRoles()![](/docs/v4.4/assets/link.svg)
On this page
Definition![](/docs/v4.4/assets/link.svg)
db.dropAllRoles( writeConcern )
Deletes all user-defined roles on the database where you run the method.
Warning
The
db.dropAllRoles()
method removes all user-defined roles from the database.Important
mongo Shell Method
This page documents a
mongo
method. This is not the documentation for database commands or language-specific drivers, such as Node.js. To use the database command, see thedropAllRolesFromDatabase
command.For MongoDB API drivers, refer to the language-specific MongoDB driver documentation.
The
db.dropAllRoles()
method takes the following argument:FieldTypeDescriptionwriteConcern
documentOptional. The level of write concern for the removal operation. ThewriteConcern
document takes the same fields as thegetLastError
command.Returns: The number of user-defined roles dropped.
Behavior![](/docs/v4.4/assets/link.svg)
Replica set![](/docs/v4.4/assets/link.svg)
If run on a replica set, db.dropAllRoles()
is executed using
"majority"
write concern by default.
Required Access![](/docs/v4.4/assets/link.svg)
You must have the dropRole
action on a database to drop a role from that database.
Example![](/docs/v4.4/assets/link.svg)
The following operations drop all user-defined roles from the products
database and uses a
write concern of majority
.
use products db.dropAllRoles( { w: "majority" } )
The method returns the number of roles dropped:
4