MongoDB grants access to data and commands through role-based authorization. MongoDB provides built-in roles that grant the different levels of access commonly needed in a database system.
A role grants privileges to perform sets of actions on defined resources. A role applies to the database on which it is defined and can grant access down to a collection level of granularity.
Each built-in role defines access at the database level for all non-system collections in the role's database and at the collection level for all system collections.
System collections include those in:
<database>.system.*namespacelocal.replset.*replica set namespace
Non-system collections are those not in namespaces in the previous list.
MongoDB Atlas database users have different built-in roles than self-hosted deployment users. However, MongoDB builds the built-in roles for each type of deployment from the same set of privilege actions.
Use the selector at the top of the page to choose your deployment type and see the available built-in roles.
MongoDB Atlas Built-In Roles
This section describes the MongoDB Atlas built-in roles and the MongoDB Roles they represent.
Create database users and assign built-in roles in the MongoDB Atlas user interface. To learn more, see Add Database Users.
To learn more about common commands that MongoDB Atlas does not support with the current MongoDB Atlas user privileges, see Unsupported Commands.
Atlas-Only Roles
The following roles are available only in MongoDB Atlas and have no corresponding self-managed MongoDB role.
killOpSessionProvides the ability to view and kill active operations, and manage sessions.
On the cluster as a whole, provides the following actions:
autoCompactProvides the ability to run the
autoCompactcommand to enable background compaction.Background compaction periodically iterates through available files and releases unneeded disk space to the operating system. To learn more about authentication requirements for
autoCompact, see Required Privileges.On the cluster as a whole, provides the following action:
manageShardBalancerProvides the ability to manage shard balancer settings, including range size and balancer status. To learn more about shard balancing, see Sharded Cluster Balancer.
On the
config.settingscollection, provides the following actions:
Protected MongoDB Database Namespaces
Avoid writing to the admin, local, and config databases, or any database prefixed with __mdb_internal_. MongoDB Atlas manages multiple collections in these databases. To learn more, see Internal Databases and System Collections.
atlasAdmin has the update privilege on the config.settings collection to manage the balancer.
Built-in Roles and Inherited Privileges
In the following table, indicates that the operation also supports timeseries collections.
MongoDB Atlas Built-in Role | MongoDB Role | Inherited Roles or Privilege Actions |
|---|---|---|
This role allows you to use
| ||
| ||
| ||
| ||
| ||
| ||
| ||
| ||
| ||
| ||
MongoDB Built-In Role Descriptions
The following are the MongoDB built-in roles used by MongoDB Atlas built-in roles.
MongoDB Role | Description |
|---|---|
| Provides minimal privileges needed for backing up data. This role provides sufficient privileges to use the MongoDB Cloud Manager backup agent, Ops Manager backup agent, or to use |
| Provides read-only access to monitoring tools, such as the MongoDB Cloud Manager and Ops Manager monitoring agent. |
| Provides the ability to perform administrative tasks such as schema-related tasks, indexing, and gathering statistics. This role does not grant privileges for user and role management. |
| Provides the same privileges as |
| Provides the ability to enable sharding for a collection and modify existing shard keys. |
| Provides read access to all non-system collections and the |
| Provides the same read-only privileges as This role grants permissions on database resources, not cluster administrative resources. |
| |
| Provides the same privileges as
This role grants permissions on database resources, not cluster administrative resources. |
Learn More
If built-in roles do not meet your requirements, create user-defined roles. For more information, see Configure Custom Database Roles.
Self-Managed Deployment Built-In Roles
MongoDB provides the following built-in roles in self-managed deployments.
To view the privileges for a built-in role, run the rolesInfo command with the showPrivileges and showBuiltinRoles fields both set to true. The following command shows the privileges for the readWrite role:
db.getRole("readWrite", { showPrivileges: true, showBuiltinRoles: true } )
{ db: 'test', role: 'readWrite', roles: [], privileges: [ { resource: { db: 'test', collection: '' }, actions: [ 'changeStream', 'cleanupStructuredEncryptionData', 'collStats', 'compactStructuredEncryptionData', 'convertToCapped', 'createCollection', 'createIndex', 'createSearchIndexes', 'dbHash', 'dbStats', 'dropCollection', 'dropIndex', 'dropSearchIndex', 'find', 'insert', 'killCursors', 'listCollections', 'listIndexes', 'listSearchIndexes', 'updateSearchIndex', 'planCacheRead', 'performRawDataOperations', 'remove', 'renameCollectionSameDB', 'update' ] }, { resource: { db: 'test', collection: 'system.js' }, actions: [ 'changeStream', 'cleanupStructuredEncryptionData', 'collStats', 'compactStructuredEncryptionData', 'convertToCapped', 'createCollection', 'createIndex', 'createSearchIndexes', 'dbHash', 'dbStats', 'dropCollection', 'dropIndex', 'dropSearchIndex', 'find', 'insert', 'killCursors', 'listCollections', 'listIndexes', 'listSearchIndexes', 'updateSearchIndex', 'planCacheRead', 'performRawDataOperations', 'remove', 'renameCollectionSameDB', 'update' ] } ], inheritedRoles: [], inheritedPrivileges: [ { resource: { db: 'test', collection: '' }, actions: [ 'changeStream', 'cleanupStructuredEncryptionData', 'collStats', 'compactStructuredEncryptionData', 'convertToCapped', 'createCollection', 'createIndex', 'createSearchIndexes', 'dbHash', 'dbStats', 'dropCollection', 'dropIndex', 'dropSearchIndex', 'find', 'insert', 'killCursors', 'listCollections', 'listIndexes', 'listSearchIndexes', 'updateSearchIndex', 'planCacheRead', 'performRawDataOperations', 'remove', 'renameCollectionSameDB', 'update' ] }, { resource: { db: 'test', collection: 'system.js' }, actions: [ 'changeStream', 'cleanupStructuredEncryptionData', 'collStats', 'compactStructuredEncryptionData', 'convertToCapped', 'createCollection', 'createIndex', 'createSearchIndexes', 'dbHash', 'dbStats', 'dropCollection', 'dropIndex', 'dropSearchIndex', 'find', 'insert', 'killCursors', 'listCollections', 'listIndexes', 'listSearchIndexes', 'updateSearchIndex', 'planCacheRead', 'performRawDataOperations', 'remove', 'renameCollectionSameDB', 'update' ] } ], isBuiltin: true }
Database User Roles
Every database includes the following client roles:
readProvides read access to all non-system collections and the
system.jscollection.Note
This role does not provide privileges to directly access the
system.namespacescollection.The role provides read access by granting the following actions:
Users without the
listDatabasesprivilege action can run thelistDatabasescommand to return a list of databases for which they have privileges. This includes databases where the user has privileges on specific collections. Run the command with theauthorizedDatabasesoption unspecified or set totrue.
Database Administration Roles
Every database includes the following database administration roles:
dbAdminProvides the ability to perform administrative tasks such as schema-related tasks, indexing, and gathering statistics. This role does not grant privileges for user and role management.
The role provides the following privileges:
ResourcePermitted Actions- All non-system collections
- (database resource)
dbOwnerThe database owner can perform any administrative action on the database. This role combines the privileges granted by the
readWrite,dbAdminanduserAdminroles.
userAdminProvides the ability to create and modify roles and users on the current database. The
userAdminrole allows users to grant any privilege to any user, including themselves. This role also indirectly provides superuser access to either the database or, if scoped to theadmindatabase, the cluster.The
userAdminrole explicitly provides the following actions:Warning
Understand the security implications of granting the
userAdminrole. A user with this role for a database can assign themselves any privilege on that database. Granting theuserAdminrole on theadmindatabase has further security implications as this indirectly provides superuser access to a cluster. Withadminscope, a user with theuserAdminrole can grant cluster-wide roles or privileges includinguserAdminAnyDatabase.
Cluster Administration Roles
The admin database includes the following roles for administering the whole system rather than just a single database. These roles include but are not limited to replica set and sharded cluster administrative functions.
clusterAdminProvides the greatest cluster-management access. This role combines the privileges granted by the
clusterManager,clusterMonitor, andhostManagerroles. The role also provides these additional permissions:dropDatabaseactionsetQuerySettingsandremoveQuerySettingsdatabase commands$querySettingsaggregation stage
clusterManagerProvides management and monitoring actions on the cluster. Users with this role can access the
configandlocaldatabases, which are used in sharding and replication, respectively. Additionally, the role provides thequerySettingsaction.ResourceActionsAll databases
clusterManagerprovides additional privileges for theconfigandlocaldatabases.On the
configdatabase, permits the following actions:ResourceActionsAll non-system collections in the
configdatabaseOn the
localdatabase, permits the following actions:ResourceActionsAll non-system collections in the
localdatabasesystem.replsetcollection
clusterMonitorProvides read-only access to monitoring tools, such as the MongoDB Cloud Manager and Ops Manager monitoring agent.
Permits the following actions on the cluster as a whole:
Permits the following actions on all databases in the cluster:
Permits the
findaction on allsystem.profilecollections in the cluster.On the
configdatabase, permits the following actions:ResourceActionsAll non-system collections in the
configdatabasesystem.jscollectionOn the
localdatabase, permits the following actions:ResourceActionsAll non-system collections in the
localdatabasesystem.jscollection
directShardOperationsStarting in MongoDB 8.0, you can use the
directShardOperationsrole to perform maintenance operations that require you to execute commands directly against a shard.Warning
Running commands using the
directShardOperationsrole can cause your cluster to stop working correctly and may cause data corruption. Only use thedirectShardOperationsrole for maintenance purposes or under the guidance of MongoDB support. Stop using thedirectShardOperationsrole when you finish performing maintenance operations.
enableShardingProvides the ability to enable sharding for a collection and modify existing shard keys.
Provides the following actions on all non-system collections:
moveCollection(MongoDB 8.0 and later)rewriteCollection(MongoDB 8.3 and later)unshardCollection(MongoDB 8.0 and later)
hostManagerProvides the ability to monitor and manage servers.
On the cluster as a whole, provides the following actions:
On all databases in the cluster, provides the following actions:
searchCoordinatorProvides
readAnyDatabaseprivileges and write permissions on the__mdb_internal_searchdatabase.Important
Do not modify the contents of the
__mdb_internal_searchdatabase.On the cluster as a whole, provides the following action:
Backup and Restoration Roles
The admin database includes the following roles for backing up and restoring data:
backupProvides minimal privileges needed for backing up data. This role provides sufficient privileges to use the MongoDB Cloud Manager backup agent, Ops Manager backup agent, or to use
mongodumpto back up an entiremongodinstance.Provides the
insertandupdateactions on thesettingscollection in theconfigdatabase.On
anyResource, provides the following actions:On the cluster as a whole, provides the following actions:
setUserWriteBlockMode(Starting in MongoDB 6.0)
Provides the
findaction on the following:All non-system collections in the cluster, including those in the
configandlocaldatabasesThe following system collections in the cluster:
system.jsandsystem.profileThe
admin.system.usersandadmin.system.rolescollectionsThe
config.settingscollectionLegacy
system.userscollections from versions of MongoDB prior to 2.6
Provides the
insertandupdateactions on theconfig.settingscollection.The
backuprole provides additional privileges to back up thesystem.profilecollection that exists when running with database profiling.
restoreProvides
convertToCappedon non-system collections.Provides the necessary privileges to restore data from backups if the data does not include
system.profilecollection data and you runmongorestorewithout the--oplogReplayoption.You need additional privileges if the backup data includes
system.profilecollection data or you run with--oplogReplay:system.profileIf the backup data includes
system.profilecollection data and the target database does not contain thesystem.profilecollection,mongorestoreattempts to create the collection even though the program does not actually restoresystem.profiledocuments. The user requires additional privileges to performcreateCollectionandconvertToCappedactions on thesystem.profilecollection for a database.Both the built-in roles
dbAdminanddbAdminAnyDatabaseprovide the additional privileges.--oplogReplayTo run with
--oplogReplay, create a user-defined role that hasanyActiononanyResource.Grant only to users who must run
mongorestorewith--oplogReplay.Provides the following action on the cluster as a whole:
Provides the following actions on all non-system collections:
Provides the following actions on
system.jscollection:Provides the following action on
anyResource:Provides the following actions on all non-system collections on the
configand thelocaldatabases:Provides the following actions on
admin.system.versionProvides the following action on
admin.system.rolesProvides the following actions on
admin.system.usersand legacysystem.userscollections:restoreincludes the ability to modify the documents in theadmin.system.userscollection using normal modification operations. However, only modify these data using the user management methods.Provides the following action on the
<database>.system.viewscollection:dropCollection(Starting in MongoDB 6.0)
On the cluster as a whole, provides the following actions:
bypassWriteBlockingMode(Staring in MongoDB 6.0)setUserWriteBlockMode(Starting in MongoDB 6.0)
All-Database Roles
The following roles are available on the admin database and provide privileges that apply to all databases except local and config:
readAnyDatabaseProvides the same read-only privileges as
readon all databases exceptlocalandconfig. The role also provides thelistDatabasesaction on the cluster as a whole.This role grants permissions on database resources, not cluster administrative resources.
See also the
clusterManagerandclusterMonitorroles for access to theconfigandlocaldatabases.
readWriteAnyDatabaseProvides the same privileges as
readWriteon all databases exceptlocalandconfig. The role also provides:the
listDatabasesaction on the cluster as a wholethe
compactStructuredEncryptionDataaction
This role grants permissions on database resources, not cluster administrative resources.
See also the
clusterManagerandclusterMonitorroles for access to theconfigandlocaldatabases.
userAdminAnyDatabaseProvides the same access to user administration operations as
userAdminon all databases exceptlocalandconfig.userAdminAnyDatabasealso provides the following privilege actions on the cluster:The role provides the following privilege actions on the
system.usersandsystem.rolescollections on theadmindatabase, and on legacysystem.userscollections from versions of MongoDB prior to 2.6:The
userAdminAnyDatabaserole does not restrict the privileges that a user can grant. As a result,userAdminAnyDatabaseusers can grant themselves privileges in excess of their current privileges and even can grant themselves all privileges, even though the role does not explicitly authorize privileges beyond user administration. This role is effectively a MongoDB system superuser.See also the
clusterManagerandclusterMonitorroles for access to theconfigandlocaldatabases.
dbAdminAnyDatabaseProvides the same privileges as
dbAdminon all databases exceptlocalandconfig. The role also provides thelistDatabasesaction on the cluster as a whole.See also the
clusterManagerandclusterMonitorroles for access to theconfigandlocaldatabases.Starting in MongoDB 5.0,
dbAdminAnyDatabaseincludes the applyOps privilege action.
Superuser Roles
Several roles provide either indirect or direct system-wide superuser access.
The following roles provide the ability to assign any user any privilege on any database. Users with one of these roles can assign themselves any privilege on any database:
dbOwnerrole, when scoped to theadmindatabaseuserAdminrole, when scoped to theadmindatabaseuserAdminAnyDatabaserole
The following role provides full privileges on all resources:
rootProvides access to the operations and all the resources of the following combined roles:
Also provides the following privilege actions:
validateonsystem.collections.On MongoDB 8.0 and later,
bypassDefaultMaxTimeMS, which causes all queries run by the user to ignore the value ofdefaultMaxTimeMS.
Internal Role
__systemMongoDB assigns this role to user objects that represent cluster members, such as replica set members and
mongosinstances. The role entitles its holder to take any action against any object in the database.Do not assign this role to user objects representing applications or human administrators, other than in exceptional circumstances.
If you need access to all actions on all resources, for example to run
applyOpscommands, do not assign this role. Instead, create a user-defined role that grantsanyActiononanyResourceand ensure that only the users who need access to these operations have this access.
Learn More
If built-in roles do not meet your requirements, create user-defined roles. For more information, see User-Defined Roles on Self-Managed Deployments.