For AI agents: a documentation index is available at https://www.mongodb.com/docs/llms.txt — markdown versions of all pages are available by appending .md to any URL path.
Docs Menu

Configure Custom Database Roles

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:

You can assign multiple custom roles to each database user.

Note

Free Cluster and Flex cluster Limitation

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.

To review the list of custom role privileges, see the API reference.

Important

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.

  • You can assign up to 20 custom roles to a single database user

  • 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 audits the creation, deletion, and updates of custom MongoDB roles in the project's Activity Feed.

  • If you assign multiple roles to a user and those roles grant conflicting permissions for an object, Atlas honors the highest permissions within any role.

    For example:

    You create two custom roles and assign both to User 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.

    User A would have all of the dbAdmin privileges for your database, since dbAdmin is the higher database access permission. User A would also have bypassDocumentValidation, since bypassDocumentValidation is the higher bypass permission.

To configure custom database roles, you must have Organization Owner, Project Owner, or Project Database Access Admin access to Atlas.

To create a custom database role for your project using the Atlas CLI, run the following command:

atlas customDbRoles create <roleName> [options]

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

To list all custom database roles for your project using the Atlas CLI, run the following command:

atlas customDbRoles list [options]

To return the details for a single custom database role in the project you specify using the Atlas CLI, run the following command:

atlas customDbRoles describe <roleName> [options]

To learn more about the syntax and parameters for the previous commands, see the Atlas CLI documentation for atlas customDbRoles list and atlas customDbRoles describe.

To update a custom database role for your project using the Atlas CLI, run the following command:

atlas customDbRoles update <roleName> [options]

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

To delete a custom database role from your project using the Atlas CLI, run the following command:

atlas customDbRoles delete <roleName> [options]

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

You cannot delete a custom role in the following scenarios:

  • When deleting the role would leave one or more child roles with no parent roles or actions.

  • When deleting the role would leave one or more database users with no roles.

You can assign custom roles in the Atlas UI when you add a database user or modify a database user. To assign custom roles through the Atlas Administration API, see Create a Database User or Update a Database User.