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

配置自定义数据库角色

You can create custom roles in Atlas when the built-in roles don't include your desired set of privileges. Atlas applies each database user's custom roles together with:

您可以为每个数据库用户分配多个自定义角色。

注意

免费集群和 Flex 集群限制

Changes to custom roles might take up to 30 seconds to deploy in Free clusters and Flex clusters.

The privilege actions available for custom roles and the custom roles API represent a subset of the privilege actions available for built-in roles.

要查看自定义角色特权列表,请参阅 API 参考资料。

重要

You must use the Atlas CLI, Atlas Administration API, Atlas UI, or a supported integration to add, modify, or delete database roles on Atlas clusters. Otherwise, Atlas rolls back any role modifications.

  • 您最多可以向单个数据库用户分配 20 个自定义角色

  • You can create up to 100 custom roles per project by default. IMPORTANT: If you require more custom roles per project, you can increase the number of custom roles up to a maximum of 1400 through the Atlas Administration API using the Set One Project Limit endpoint.

  • Atlas 审核项目操作日志中的自定义 MongoDB 角色的创建、删除和更新操作

  • 如果为用户分配了多个角色,而这些角色授予 某个对象的权限相互冲突,则 Atlas 会尊重任何角色内的 最高权限。

    例如:

    您创建两个自定义角色,并将其分配给用户 A:

    • The first custom role grants only read privileges on your database. It also grants bypassDocumentValidation on your database.

    • The second role grants dbAdmin privileges on your database. It doesn't grant bypassDocumentValidation, which is an implicit denial of bypass permissions.

    用户 A 将拥有数据库的所有 dbAdmin 特权,因为 dbAdmin 是更高的数据库访问权限。用户 A 还可以 bypassDocumentValidation,因为 bypassDocumentValidation 是更高的绕过权限。

要配置自定义数据库角色,您必须拥有 Atlas 的 Organization Owner、Project Owner 或 Project Database Access Admin 访问权限。

如需使用 Atlas CLI 创建项目的自定义数据库角色,请运行以下命令:

atlas customDbRoles create <roleName> [options]

要了解有关命令语法和参数的更多信息,请参阅 Atlas CLI 文档中的 atlas customDbRoles create。

如需使用 Atlas CLI 列出项目的所有自定义数据库角色,请运行以下命令:

atlas customDbRoles list [options]

如需使用 Atlas CLI 返回指定项目中单个自定义数据库角色的详细信息,请运行以下命令:

atlas customDbRoles describe <roleName> [options]

要详细了解先前命令的语法和参数,请参阅 Atlas CLI 文档中的 atlas customDbRoles list 和 atlas customDbRoles describe。

提示

请参阅:相关链接

如需使用 Atlas CLI 更新项目的自定义数据库角色, 请运行以下命令:

atlas customDbRoles update <roleName> [options]

要了解有关命令语法和参数的更多信息,请参阅 Atlas CLI 文档中的 atlas customDbRoles update。

如需使用 Atlas CLI 删除项目的自定义数据库角色, 请运行以下命令:

atlas customDbRoles delete <roleName> [options]

To learn more about the command syntax and parameters, see the Atlas CLI documentation for atlas customDbRoles delete.

出现以下情况时无法删除自定义角色:

  • 删除角色后,一个或多个子角色将没有父角色或操作。

  • 当删除角色会导致一个或多个数据库用户没有角色时。

添加数据库用户或修改数据库用户时,可以在 Atlas 用户界面中分配自定义角色。要通过 Atlas Administration API 分配自定义角色,请参阅创建数据库用户或更新数据库用户。