MongoDB grants access to data and commands through role-based authorization and provides built-in roles that provide the different levels of access commonly needed in a database system. You can additionally create user-defined roles.
A role grants privileges to perform sets of actions on defined resources. A given role applies to the database on which it is defined and can grant access down to a collection level of granularity.
System collections include those in:
- <database>.system.*namespace
- local.replset.*replica set namespace
For details, see System Collections.
Non-system collections are those not in namespaces in the previous list.
Each of MongoDB's built-in roles 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.
This section describes the privileges for each built-in role. You can also
view the privileges for a built-in role at any time by issuing the
rolesInfo command with the showPrivileges and
showBuiltinRoles fields both set to true.
MongoDB Atlas Built-In Roles
Although database users in MongoDB Atlas have different built-in roles than self-hosted deployments, the built-in roles for each type of deployment are built from the same set of privilege actions.
For the built-in database user roles for deployments hosted in MongoDB Atlas, see Atlas Built-In Roles and Privileges.
You can create database users and assign built-in roles in the MongoDB Atlas user interface. To learn more, see Add Database Users.
Database Built-In Roles
MongoDB provides the following built-in roles in self-hosted deployments:
- Database user and database administration roles on specific databases 
- All other roles only on the - admindatabase
Database User Roles
Every database includes the following client roles:
- read
- Provides the ability to read data on all non-system collections and the - system.jscollection.- Note- The role does not provide privileges to directly access the - system.namespacescollection directly.- The role provides read access by granting the following actions: - If the user does not have the - listDatabasesprivilege action, users can run the- listDatabasescommand to return a list of databases for which the user has privileges (including databases for which the user has privileges on specific collections) if the command is run with- authorizedDatabasesoption unspecified or set to- true.
Database Administration Roles
Every database includes the following database administration roles:
- dbAdmin
- 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. - Specifically, the role provides the following privileges: ResourcePermitted Actions- All non-system collections (i.e. database resource) 
- dbOwner
- The database owner can perform any administrative action on the database. This role combines the privileges granted by the - readWrite,- dbAdminand- userAdminroles.
- userAdmin
- Provides the ability to create and modify roles and users on the current database. Since the - userAdminrole allows users to grant any privilege to any user, including themselves, the role also indirectly provides superuser access to either the database or, if scoped to the- admindatabase, the cluster.- The - userAdminrole explicitly provides the following actions:- Warning- It is important to 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 the- userAdminrole on the- admindatabase has further security implications as this indirectly provides superuser access to a cluster. With- adminscope a user with the- userAdminrole can grant cluster-wide roles or privileges including- userAdminAnyDatabase.
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.
- clusterAdmin
- Provides the greatest cluster-management access. This role combines the privileges granted by the - clusterManager,- clusterMonitor, and- hostManagerroles. Additionally, the role provides the- dropDatabaseaction.
- clusterManager
- Provides management and monitoring actions on the cluster. A user with this role can access the - configand- localdatabases, which are used in sharding and replication, respectively. Additionally, the role provides the- querySettingsaction.ResourceActions- All databases - clusterManagerprovides additional privileges for the- configand- localdatabases.- On the - configdatabase, permits the following actions:ResourceActions- All non-system collections in the - configdatabase- On the - localdatabase, permits the following actions:ResourceActions- All non-system collections in the - localdatabase- system.replsetcollection
- clusterMonitor
- Provides 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 all- system.profilecollections in the cluster.- On the - configdatabase, permits the following actions:ResourceActions- All non-system collections in the - configdatabase- system.jscollection- On the - localdatabase, permits the following actions:ResourceActions- All non-system collections in the - localdatabase- system.jscollection
- directShardOperations
- Starting 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 the- directShardOperationsrole for maintenance purposes or under the guidance of MongoDB support. Once you are done performing maintenance operations, stop using the- directShardOperationsrole.
- enableSharding
- Provides 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)
- unshardCollection(MongoDB 8.0 and later)
 
- hostManager
- Provides the ability to monitor and manage servers. - On the cluster as a whole, provides the following actions: - compact(New in version 7.3)
 - rotateCertificates(New in version 5.0)
 - On all databases in the cluster, provides the following actions: 
- searchCoordinator
- Provides - 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:
- backup
- 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 - mongodumpto back up an entire- mongodinstance.- Provides the - insertand- updateactions on the- settingscollection in the- configdatabase.- On - anyResource, provides the- listDatabasesaction
- listCollectionsaction
- listIndexesaction
- listSearchIndexesaction
 - On the cluster as a whole, provides the - setUserWriteBlockMode(Starting in MongoDB 6.0)
 - Provides the - findaction on the following:- all non-system collections in the cluster, including those in the - configand- localdatabases
- The following system collections in the cluster: - system.js, and- system.profile
- The - admin.system.usersand- admin.system.rolescollections
- The - config.settingscollection
- Legacy - system.userscollections from versions of MongoDB prior to 2.6
 - Provides the - insertand- updateactions on the- config.settingscollection.- The - backuprole provides additional privileges to back up the- system.profilecollection that exists when running with database profiling.
- restore
- Provides - convertToCappedon non-system collections.- Provides the necessary privileges to restore data from backups if the data does not include - system.profilecollection data and you run- mongorestorewithout the- --oplogReplayoption.- If the backup data includes - system.profilecollection data or you run with- --oplogReplay, you need additional privileges:- system.profile- If the backup data includes - system.profilecollection data and the target database does not contain the- system.profilecollection,- mongorestoreattempts to create the collection even though the program does not actually restore- system.profiledocuments. As such, the user requires additional privileges to perform- createCollectionand- convertToCappedactions on the- system.profilecollection for a database.- Both the built-in roles - dbAdminand- dbAdminAnyDatabaseprovide the additional privileges.- --oplogReplay- To run with - --oplogReplay, create a user-defined role that has- anyActionon- anyResource.- 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 the- localdatabases:- Provides the following actions on - admin.system.version- Provides the following action on - admin.system.roles- Provides the following actions on - admin.system.usersand legacy- system.userscollections:- Although, - restoreincludes the ability to modify the documents in the- admin.system.userscollection using normal modification operations, 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 which apply to all databases except local and
config:
- readAnyDatabase
- Provides the same read-only privileges as - readon all databases except- localand- config. The role also provides the- listDatabasesaction on the cluster as a whole.- See also the - clusterManagerand- clusterMonitorroles for access to the- configand- localdatabases.
- readWriteAnyDatabase
- Provides the same privileges as - readWriteon all databases except- localand- config. The role also provides:- the - listDatabasesaction on the cluster as a whole
- the - compactStructuredEncryptionDataaction
 - See also the - clusterManagerand- clusterMonitorroles for access to the- configand- localdatabases.
- userAdminAnyDatabase
- Provides the same access to user administration operations as - userAdminon all databases except- localand- config.- userAdminAnyDatabasealso provides the following privilege actions on the cluster:- The role provides the following privilege actions on the - system.usersand- system.rolescollections on the- admindatabase, and on legacy- system.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 - clusterManagerand- clusterMonitorroles for access to the- configand- localdatabases.
- dbAdminAnyDatabase
- Provides the same privileges as - dbAdminon all databases except- localand- config. The role also provides the- listDatabasesaction on the cluster as a whole.- See also the - clusterManagerand- clusterMonitorroles for access to the- configand- localdatabases.- 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, which means that users with one of these roles can assign themselves any privilege on any database:
- dbOwnerrole, when scoped to the- admindatabase
- userAdminrole, when scoped to the- admindatabase
- userAdminAnyDatabaserole
The following role provides full privileges on all resources:
- root
- Provides access to the operations and all the resources of the following roles combined: - Also provides the following privilege actions: - validateon- system.collections.
- On MongoDB 8.0 and later, - bypassDefaultMaxTimeMS, which causes all queries run by the user to ignore the value of- defaultMaxTimeMS.
 
Internal Role
- __system
- MongoDB 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 grants- anyActionon- anyResourceand ensure that only the users who need access to these operations have this access.