Docs Menu

Docs HomeMongoDB Manual


On this page

  • Definition
  • Behavior
  • Required Access
  • Example
db.dropAllRoles( writeConcern )

Deletes all user-defined roles on the database where you run the method.


The db.dropAllRoles() method removes all user-defined roles from the database.


mongosh Method

This page documents a mongosh method. This is not the documentation for database commands or language-specific drivers, such as Node.js.

For the database command, see the dropAllRolesFromDatabase command.

For MongoDB API drivers, refer to the language-specific MongoDB driver documentation.

For the legacy mongo shell documentation, refer to the documentation for the corresponding MongoDB Server release:

mongo shell v4.4

The db.dropAllRoles() method takes the following argument:


Optional. The level of write concern for the operation. See Write Concern Specification.

Returns:The number of user-defined roles dropped.

If run on a replica set, db.dropAllRoles() is executed using "majority" write concern by default.

You must have the dropRole action on a database to drop a role from that database.

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:

←  db.dropRole()db.getRole() →
Share Feedback
© 2023 MongoDB, Inc.


  • Careers
  • Investor Relations
  • Legal Notices
  • Privacy Notices
  • Security Information
  • Trust Center
© 2023 MongoDB, Inc.