dropUser

On this page本页内容

Definition定义

dropUser

Removes the user from the database on which you run the command. 从运行命令的数据库中删除用户。The dropUser command has the following syntax:dropUser命令具有以下语法:

{
  dropUser: "<user>",
  writeConcern: { <write concern> },
  comment: <any>
}

The dropUser command document has the following fields:dropUser命令文档包含以下字段:

Field字段Type类型Description描述
dropUserstringThe name of the user to delete. 要删除的用户的名称。You must issue the dropUser command while using the database where the user exists.在使用用户所在的数据库时,必须发出dropUser命令。
writeConcerndocument

Optional. 可选。The level of write concern for the operation. See Write Concern Specification.操作的写入关注级别。请参阅写入关注规范

commentany

Optional. 可选。A user-provided comment to attach to this command. 用户提供了附加到此命令的注释。Once set, this comment appears alongside records of this command in the following locations:设置后,此注释将与此命令的记录一起显示在以下位置:

A comment can be any valid BSON type(string, integer, object, array, etc).注释可以是任何有效的BSON类型(字符串、整数、对象、数组等)。

New in version 4.4.在版本4.4中新增

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

Required Access所需访问权限

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

Example示例

The following sequence of operations in mongosh removes reportUser1 from the products database:mongosh中的以下操作序列从products数据库中删除reportUser1

use products
db.runCommand( {
   dropUser: "reportUser1",
   writeConcern: { w: "majority", wtimeout: 5000 }
} )
←  dropAllUsersFromDatabasegrantRolesToUser →