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

dropAllRolesFromDatabase(数据库命令)

dropAllRolesFromDatabase

删除运行命令的数据库上的所有用户定义角色。

警告

The dropAllRolesFromDatabase removes all user-defined roles from the database.

提示

In mongosh, this command can also be run through the db.dropAllRoles() 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: The fully managed service for MongoDB deployments in the cloud

重要

This command is not supported in M0 and Flex clusters. For more information, see Unsupported Commands.

该命令具有以下语法:

db.runCommand(
{
dropAllRolesFromDatabase: 1,
writeConcern: { <write concern> },
comment: <any>
}
)

该命令具有以下字段:

字段
类型
说明

dropAllRolesFromDatabase

整型

指定1以从运行该命令的数据库中删除所有用户定义的角色。

writeConcern

文档

/includes/source/fact-写关注(write concern)-spec-link.rst

comment

any

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

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

必须对数据库执行dropRole操作才能从该数据库中删除角色。

以下操作会从products数据库中删除所有用户定义的角色:

use products
db.runCommand(
{
dropAllRolesFromDatabase: 1,
writeConcern: { w: "majority" }
}
)

结果文档中的n字段报告删除的角色数量:

{ "n" : 4, "ok" : 1 }