对于 AI 代理:可在 https://www.mongodb.com/zh-cn/docs/llms.txt 获取文档索引—通过在任何 URL 路径后添加 .md 可获取所有页面的 Markdown 版本。
Docs 菜单

dropUser(数据库命令)

dropUser

从运行命令的数据库中删除用户。

提示

In mongosh, this command can also be run through the db.dropUser() helper method.

Helper methods are convenient for mongosh users, but they may not return the same level of information as database commands. In cases where the convenience is not needed or the additional return fields are required, use the database command.

此命令可用于以下环境中托管的部署:

重要

MongoDB Atlas 集群不支持此命令。有关 Atlas 对所有命令的支持的信息,请参阅不支持的命令

该命令具有以下语法:

db.runCommand(
{
dropUser: "<user>",
writeConcern: { <write concern> },
comment: <any>
}
)

该命令具有以下字段:

字段
类型
说明

dropUser

字符串

要删除的用户的名称。使用用户所在的数据库时,必须发出dropUser 命令。

writeConcern

文档

可选。操作的写关注级别。请参阅写关注规范

comment

any

可选。用户提供的待附加到该命令的注释。设置后,该注释将与该命令的记录一起出现在以下位置:

注释可以是任何有效的 BSON 类型(字符串、整型、对象、数组等)。

在删除具有 userAdminAnyDatabase 角色的用户之前,确保至少有另一个用户具有用户管理特权。

必须在数据库中执行dropUser动作,才能将用户从该数据库中删除。

mongoshreportUser1中的以下操作序列会从products 数据库中删除 :

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