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

db.dropUser()(mongosh方法)

db.dropUser(username, writeConcern)

从当前数据库中删除用户。

重要

mongosh 方法

This page documents a mongosh method. This is not the documentation for database commands or language-specific drivers, such as Node.js.

有关数据库命令,请参阅 dropUser 命令。

如需了解 MongoDB API 驱动程序,请参阅特定语言的 MongoDB 驱动程序文档。

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

Parameter
类型
说明

username

字符串

要从数据库中删除的用户名。

writeConcern

文档

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

The db.dropUser() method wraps the dropUser command.

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

此方法可用于以下环境中托管的部署:

重要

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

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

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

The following db.dropUser() operation drops the reportUser1 user on the products database.

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