Docs Menu

Docs HomeMongoDB Manual

db.dropAllUsers()

On this page

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

Removes all users from the current database.

Warning

The db.dropAllUsers() method removes all users from the database.

The db.dropAllUsers() method takes the following arguments:

Field
Type
Description
writeConcern
document

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

The db.dropAllUsers() method wraps the dropAllUsersFromDatabase command.

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

You must have the dropUseraction on a database to drop a user from that database.

The following db.dropAllUsers() operation drops every user from the products database.

use products
db.dropAllUsers( {w: "majority", wtimeout: 5000} )

The n field in the results document shows the number of users removed:

{ "n" : 12, "ok" : 1 }
←  db.dropUser()db.getUser() →
Give Feedback
© 2022 MongoDB, Inc.

About

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