db.dropAllRoles()

Definition

  • db.dropAllRoles(writeConcern)
  • Deletes all user-defined roles on thedatabase where you run the method.

Warning

The dropAllRoles method removes alluser-defined roles from the database.

The dropAllRoles method takes the following argument:

FieldTypeDescriptionwriteConcerndocumentOptional. The level of write concern for theremoval operation. The writeConcern document takes the samefields as the getLastError command.

Returns:The number of user-defined roles dropped.

The db.dropAllRoles() method wraps thedropAllRolesFromDatabase command.

Behavior

Replica set

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

Required Access

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

Example

The following operations drop all user-defined roles from the products database and uses awrite concern of majority.

  1. use products
  2. db.dropAllRoles( { w: "majority" } )

The method returns the number of roles dropped:

  1. 4