Updated on 2024-01-18 GMT+08:00

Deleting a User

db.dropUser(username, writeConcern)
  • username is the name of the user to be deleted from the database.
  • writeConcern: The level of write concern for the removal operation. This parameter is optional.

Example

The following describes how to delete user reportUser1 from database products.

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

After the user is deleted, null is displayed when you run the db.getUser command.

replica:PRIMARY> db.getUser("reportUser1")
null