Docs Menu
Docs Home
/ /

Built-In Roles

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.

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.

MongoDB provides the following built-in roles in self-hosted deployments:

Every database includes the following client roles:

read

Provides the ability to read data on all non-system collections and the system.js collection.

Note

The role does not provide privileges to directly access the system.namespaces collection directly.

The role provides read access by granting the following actions:

If the user does not have the listDatabases privilege action, users can run the listDatabases command 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 authorizedDatabases option unspecified or set to true.

readWrite

Provides all the privileges of the read role plus ability to modify data on all non-system collections and the system.js collection.

The role provides the following actions on those collections:

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:

Resource
Permitted 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, dbAdmin and userAdmin roles.

userAdmin

Provides the ability to create and modify roles and users on the current database. Since the userAdmin role 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 admin database, the cluster.

The userAdmin role explicitly provides the following actions:

Warning

It is important to understand the security implications of granting the userAdmin role: a user with this role for a database can assign themselves any privilege on that database. Granting the userAdmin role on the admin database has further security implications as this indirectly provides superuser access to a cluster. With admin scope a user with the userAdmin role can grant cluster-wide roles or privileges including userAdminAnyDatabase.

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 hostManager roles. Additionally, the role provides the dropDatabase action.

clusterManager

Provides management and monitoring actions on the cluster. A user with this role can access the config and local databases, which are used in sharding and replication, respectively. Additionally, the role provides the querySettings action.

On the config database, permits the following actions:

On the local database, permits the following actions:

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 find action on all system.profile collections in the cluster.

On the config database, permits the following actions:

On the local database, permits the following actions:

directShardOperations

Starting in MongoDB 8.0, you can use the directShardOperations role to perform maintenance operations that require you to execute commands directly against a shard.

Warning

Running commands using the directShardOperations role can cause your cluster to stop working correctly and may cause data corruption. Only use the directShardOperations role for maintenance purposes or under the guidance of MongoDB support. Once you are done performing maintenance operations, stop using the directShardOperations role.

enableSharding

Provides the ability to enable sharding for a collection and modify existing shard keys.

Provides the following actions on all non-system collections:

hostManager

Provides 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:

searchCoordinator

Provides readAnyDatabase privileges and write permissions on the __mdb_internal_search database.

Important

Do not modify the contents of the __mdb_internal_search database.

On the cluster as a whole, provides the following action:

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 mongodump to back up an entire mongod instance.

Provides the insert and update actions on the settings collection in the config database.

On anyResource, provides the

On the cluster as a whole, provides the

Provides the find action on the following:

Provides the insert and update actions on the config.settings collection.

The backup role provides additional privileges to back up the system.profile collection that exists when running with database profiling.

restore

Provides convertToCapped on non-system collections.

Provides the necessary privileges to restore data from backups if the data does not include system.profile collection data and you run mongorestore without the --oplogReplay option.

If the backup data includes system.profile collection data or you run with --oplogReplay, you need additional privileges:

system.profile

If the backup data includes system.profile collection data and the target database does not contain the system.profile collection, mongorestore attempts to create the collection even though the program does not actually restore system.profile documents. As such, the user requires additional privileges to perform createCollection and convertToCapped actions on the system.profile collection for a database.

Both the built-in roles dbAdmin and dbAdminAnyDatabase provide the additional privileges.

--oplogReplay

To run with --oplogReplay, create a user-defined role that has anyAction on anyResource.

Grant only to users who must run mongorestore with --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.js collection:

Provides the following action on anyResource:

Provides the following actions on all non-system collections on the config and the local databases:

Provides the following actions on admin.system.version