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

db.dropAllRoles()(mongosh方法)

db.dropAllRoles( writeConcern )

删除运行该方法的数据库上的所有用户定义角色。

警告

The db.dropAllRoles() method removes all user-defined roles from the database.

重要

mongosh 方法

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

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

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

The db.dropAllRoles() method takes the following argument:

字段
类型
说明

writeConcern

文档

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

返回:

删除的用户定义角色的数量。

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

重要

This command is not supported in MongoDB Atlas clusters. For information on Atlas support for all commands, see Unsupported Commands.

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

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

以下操作从products数据库中删除所有用户定义的角色,并使用写关注majority 。

use products
db.dropAllRoles( { w: "majority" } )

该方法返回删除的角色数量:

4