Database Manual / Reference / mongosh Methods / User Management

db.dropUser() (mongosh method方法)

Definition定义

db.dropUser(username, writeConcern)

Removes the user from the current database.从当前数据库中删除用户。

Important

mongosh Method方法

This page documents a mongosh method. This is not the documentation for database commands or language-specific drivers, such as Node.js.本页记录了一种mongosh方法。这不是数据库命令或特定语言驱动程序(如Node.js)的文档。

For the database command, see the dropUser command.有关数据库命令,请参阅dropUser命令。

For MongoDB API drivers, refer to the language-specific MongoDB driver documentation.有关MongoDB API驱动程序,请参阅特定语言的MongoDB驱动程序文档

The db.dropUser() method takes the following arguments:db.dropUser()方法接受以下参数:

Parameter参数Type类型Description描述
usernamestring字符串The name of the user to remove from the database.要从数据库中删除的用户名。
writeConcerndocument文档Optional. 可选。The level of write concern for the operation. See Write Concern Specification.操作的写入关注级别。请参阅写入关注规范

The db.dropUser() method wraps the dropUser command.db.dropUser()方法封装dropUser命令。

Before dropping a user who has the userAdminAnyDatabase role, ensure you have at least another user with user administration privileges.在删除具有userAdminAnyDatabase角色的用户之前,请确保您至少有另一个具有用户管理权限的用户。

Compatibility兼容性

This method is available in deployments hosted in the following environments:此方法在以下环境中托管的部署中可用:

Important

This command is not supported in MongoDB Atlas clusters. MongoDB Atlas集群不支持此命令。For information on Atlas support for all commands, see Unsupported Commands.有关Atlas支持所有命令的信息,请参阅不支持的命令

  • MongoDB Enterprise: The subscription-based, self-managed version of MongoDB:MongoDB的基于订阅的自我管理版本
  • MongoDB Community: The source-available, free-to-use, and self-managed version of MongoDB:MongoDB的源代码可用、免费使用和自我管理版本

Behavior行为

Replica set副本集

If run on a replica set, db.dropUser() is executed using "majority" write concern by default.如果在副本集上运行db.dropUser(),默认情况下使用"majority"写关注执行。

Required Access所需访问权限

You must have the dropUser action on a database to drop a user from that database.您必须对数据库执行dropUser操作,才能从该数据库中删除用户。

Example示例

The following db.dropUser() operation drops the reportUser1 user on the products database.以下db.dropUser()操作将reportUser1用户删除到产品数据库中。

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