Privilege Actions
On this page
Privilege actions define the operations a user can perform on a resource. A MongoDB privilege comprises a resource and the permitted actions. This page lists available actions grouped by common purpose.
MongoDB provides built-in roles with pre-defined pairings of resources and permitted actions. For lists of the actions granted, see Built-In Roles. To define custom roles, see Create a User-Defined Role.
Query and Write Actions
find-
User can perform the following commands, and their equivalent helper methods:
-
aggregatefor all pipeline operations except$collStats,$out, and$indexStats. -
geoSearch(Removed in MongoDB 5.0) -
getLastError(Removed in MongoDB 5.1) -
killCursors, provided that the cursor is associated with a currently authenticated user. -
mapReducewith the{out: inline}option. -
resetError(Removed in MongoDB 5.0)
Required for the query portion of the
mapReducecommand anddb.collection.mapReduce()helper method when outputting to a collection.Required for the query portion of the
findAndModifycommand anddb.collection.findAndModify()helper method.Required on the source collection for the
cloneCollectionAsCappedandrenameCollectioncommands and thedb.collection.renameCollection()helper method.If the user does not have the
listDatabasesprivilege action, users can run thelistDatabasescommand 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 withauthorizedDatabasesoption unspecified or set totrue.Apply this action to database or collection resources.
-
insert-
User can perform the following commands and their equivalent methods:
Required for the output portion of the
mapReducecommand anddb.collection.mapReduce()helper method when outputting to a collection.Required for the
aggregatecommand anddb.collection.aggregate()helper method when using the$outor$mergepipeline operator.Required for the
updateandfindAndModifycommands and equivalent helper methods when used with theupsertoption.Required on the destination collection for the following commands and their helper methods:
Apply this action to database or collection resources.
remove-
User can perform the
deletecommand and equivalent helper method.Required for the write portion of the
findAndModifycommand anddb.collection.findAndModify()method.Required for the
mapReducecommand anddb.collection.mapReduce()helper method when you specify thereplaceaction when outputting to a collection.Required for the
aggregatecommand anddb.collection.aggregate()helper method when using the$outpipeline operator.Apply this action to database or collection resources.
update-
User can perform the
updatecommand and equivalent helper methods.Required for the
mapReducecommand anddb.collection.mapReduce()helper method when outputting to a collection without specifying thereplaceaction.Required for the
findAndModifycommand anddb.collection.findAndModify()helper method.Apply this action to database or collection resources.
bypassDocumentValidation-
Users can bypass document validation on commands and methods that support the
bypassDocumentValidationoption. The following commands and their equivalent methods support bypassing document validation:Apply this action to database or collection resources.
useUUID-
User can execute the following commands using a UUID as if it were a namespace:
For example, this privilege authorizes a user to run the following command which executes a
findcommand on a collection with the given UUID. In order to be successful, this operation also requires that the user is authorized to execute thefindcommand on the collection namespace corresponding to the given UUID.db.runCommand({find: UUID("123e4567-e89b-12d3-a456-426655440000")})
For more information on collection UUIDs, see Collections.
Apply this action to the
clusterresource.
Database Management Actions
changeCustomData-
User can change the custom information of any user in the given database. Apply this action to database resources.
changeOwnCustomData-
Users can change their own custom information. Apply this action to database resources. See also Change Your Password and Custom Data.
changeOwnPassword-
Users can change their own passwords. Apply this action to database resources. See also Change Your Password and Custom Data.
changePassword-
User can change the password of any user in the given database. Apply this action to database resources.
createCollection-
User can perform the
db.createCollection()method. Apply this action to database or collection resources.
createIndex-
Provides access to the
db.collection.createIndex()method and thecreateIndexescommand. Apply this action to database or collection resources.
createRole-
User can create new roles in the given database. Apply this action to database resources.
createUser-
User can create new users in the given database. Apply this action to database resources.
dropCollection-
User can perform the
db.collection.drop()method. Apply this action to database or collection resources.
enableProfiler-
User can perform the
db.setProfilingLevel()method. Apply this action to database resources.
grantRole-
User can grant any role in the database to any user from any database in the system. Apply this action to database resources.
killCursors-
Starting in MongoDB 4.2, users can always kill their own cursors, regardless of whether the users have the privilege to
killCursors. As such, thekillCursorsprivilege has no effect in MongoDB 4.2+.In MongoDB 3.6.3 through MongoDB 4.0.x, users require
killCursorsprivilege to kill their own curors when access control is enabled. Cursors are associated with the users at the time of cursor creation. Apply this action to collection resources.
killAnyCursor-
User can kill any cursor, even cursors created by other users. Apply this action to collection resources.
planCacheIndexFilter-
User can run the
planCacheClearFilters,planCacheListFilters, andplanCacheSetFiltercommands. Apply theplanCacheIndexFilteraction to collection resources.
revokeRole-
User can remove any role from any user from any database in the system. Apply this action to database resources.
setAuthenticationRestriction-
User can specify the authenticationRestrictions field in the
userdocument when running the following commands:User can specify the
authenticationRestrictionsfield in theroledocument when running the following commands:Note
The following built-in roles grant this privilege:
-
The
userAdminrole provides this privilege on the database that the role is assigned. -
The
userAdminAnyDatabaserole provides this privilege on all databases.
Transitively, the
restoreandrootroles also provide this privilege.Apply this action to database resources.
-
setFeatureCompatibilityVersion-
User can run the
setFeatureCompatibilityVersioncommand. Apply this action to theclusterresource.
unlock-
User can perform the
db.fsyncUnlock()method. Apply this action to theclusterresource.
Deployment Management Actions
authSchemaUpgrade-
User can perform the
authSchemaUpgradecommand. Apply this action to theclusterresource.
cleanupOrphaned-
User can perform the
cleanupOrphanedcommand. Apply this action to theclusterresource.
inprog-
User can use the
db.currentOp()method to return information on pending and active operations. Apply this action to theclusterresource.
invalidateUserCache-
Provides access to the
invalidateUserCachecommand. Apply this action to theclusterresource.
killop-
User can perform the
db.killOp()method. Apply this action to theclusterresource.
planCacheRead-
User can run the following operations:
-
$planCacheStatsaggregation stage.
Apply this action to database or collection resources.
-
planCacheWrite-
User can perform the
planCacheClearcommand and thePlanCache.clear()andPlanCache.clearPlansByQuery()methods. Apply this action to database or collection resources.
Change Stream Actions
changeStream-
User with
changeStreamandfindon the specific collection, all non-systemcollections in a specific database, or all non-systemcollections across all databases can open change stream cursor for that resource.
Replication Actions
replSetGetConfig-
User can view a replica set's configuration. Provides access to the
replSetGetConfigcommand andrs.conf()helper method.Apply this action to the
clusterresource.
replSetGetStatus-
User can perform the
replSetGetStatuscommand. Apply this action to theclusterresource.
replSetHeartbeat-
User can perform the deprecated
replSetHeartbeatcommand. Apply this action to theclusterresource.
replSetStateChange-
User can change the state of a replica set through the
replSetFreeze,replSetMaintenance,replSetStepDown, andreplSetSyncFromcommands. Apply this action to theclusterresource.
Sharding Actions
addShard-
User can perform the
addShardcommand. Apply this action to theclusterresource.
clearJumboFlag-
Available starting in 4.2.3 and 4.0.15
Required to clear a chunk's jumbo flag using the
clearJumboFlagcommand. Apply this action to database or collection resources.Included in the
clusterManagerbuilt-in role.
enableShardingNote
Applicable Resources
The action can apply to either:
-
Database or collection resource to enable sharding for a database or shard a collection.
-
Cluster resource to perform various shard zone operations (Starting in version 4.2.2, 4.0.14, 3.6.16).
Resources Description Grants users privileges to perform the following operations: - Enable sharding on a database using the
enableShardingcommand, and - Shard a collection using the
shardCollectioncommand.
Starting in version 4.2.2, 4.0.14, 3.6.16Grants users privileges to perform the following shard zone operations: You can also perform these shard zone operations if you have find/updateactions on the appropriate collections in theconfigdatabase. Refer to the specific operations for details.-
refineCollectionShardKey-
Provides privileges to refine the shard key for a sharded collection; i.e. run the
refineCollectionShardKeycommand. Apply this action to database or collection resource.Included in the
clusterManagerbuilt-in role.New in version 4.4.
flushRouterConfig-
User can perform the
flushRouterConfigcommand. Apply this action to theclusterresource.
getShardMap-
User can perform the
getShardMapcommand. Apply this action to theclusterresource.
getShardVersion-
User can perform the
getShardVersioncommand. Apply this action to database resources.
listShards-
User can perform the
listShardscommand. Apply this action to theclusterresource.
moveChunk-
User can perform the
moveChunkandmoveRangecommands. In addition, user can perform themovePrimarycommand provided that the privilege is applied to an appropriate database resource. Apply this action to database or collection resources.
removeShard-
User can perform the
removeShardcommand. Apply this action to theclusterresource.
shardedDataDistribution-
User can perform the
$shardedDataDistributionaggregation pipeline stage.New in version 6.0.3.
shardingState-
User can perform the
shardingStatecommand. Apply this action to theclusterresource.
splitVector-
User can perform the
splitVectorcommand. Apply this action to database or collection resources.
Server Administration Actions
applicationMessage-
User can perform the
logApplicationMessagecommand. Apply this action to theclusterresource.
bypassWriteBlockingMode-
User can perform writes even when writes are blocked by the
setUserWriteBlockModecommand. Apply this action to theclusterresource.
closeAllDatabases-
User can perform the deprecated
closeAllDatabasescommand. Apply this action to theclusterresource.
collMod-
User can perform the
collModcommand. Apply this action to database or collection resources.
compact-
User can perform the
compactcommand. Apply this action to database or collection resources.
compactStructuredEncryptionData-
User can perform the
compactStructuredEncryptionDatacommand. Apply this action to database or collection resources.
connPoolSync-
User can perform the internal
connPoolSynccommand. Apply this action to theclusterresource.
convertToCapped-
User can perform the
convertToCappedcommand. Apply this action to database or collection resources.
dropConnections-
User can perform the
dropConnectionscommand. Apply this action to theclusterresource.
dropDatabase-
User can perform the
dropDatabasecommand. Apply this action to database resources.
dropIndex-
User can perform the
dropIndexescommand. Apply this action to database or collection resources.
forceUUID-
User can create a collection with a user-defined collection UUID using the
applyOpscommand.Apply this action to the
clusterresource.
fsync-
User can perform the
fsynccommand. Apply this action to theclusterresource.
getDefaultRWConcern-
User can issue the administrative
getDefaultRWConcerncommand. Apply this action to theclusterresource.
getParameter-
User can perform the
getParametercommand. Apply this action to theclusterresource.
hostInfo-
Provides information about the server the MongoDB instance runs on. Apply this action to the
clusterresource.
oidReset-
Required to reset the 5 byte random string that is used in the ObjectID.
logRotate-
User can perform the
logRotatecommand. Apply this action to theclusterresource.
reIndex-
User can perform the
reIndexcommand. Apply this action to database or collection resources.
renameCollectionSameDB-
Allows the user to rename collections on the current database using the
renameCollectioncommand. Apply this action to database resources.Additionally, the user must either have
findon the source collection or not havefindon the destination collection.If a collection with the new name already exists, the user must also have the
dropCollectionaction on the destination collection.
rotateCertificates-
User can perform the
rotateCertificatescommand command. Apply this action to theclusterresource.
setDefaultRWConcern-
User can issue the administrative
setDefaultRWConcerncommand. Apply this action to theclusterresource.
setParameter-
User can perform the
setParametercommand. Apply this action to theclusterresource.
setUserWriteBlockMode-
User can perform the
setUserWriteBlockModecommand. Apply this action to theclusterresource.
shutdown-
User can perform the
shutdowncommand. Apply this action to theclusterresource.
Session Actions
impersonate-
User can perform the
killAllSessionsByPatterncommand withusersandrolespattern. Apply this action to theclusterresource.To run
killAllSessionsByPatterncommand, users must also havekillAnySessionprivileges on the cluster resource.
listSessions-
User can perform the
$listSessionsoperation or$listLocalSessionsoperation for all users or specified user(s). Apply this action to theclusterresource.
killAnySession-
User can perform the
killAllSessionsand thekillAllSessionsByPatterncommand. Apply this action to theclusterresource.Tip
See also:
Free Monitoring Actions
checkFreeMonitoringStatus-
User with this action on the
clusterresource can check the status of Free Monitoring.New in version 4.0.
setFreeMonitoring-
User with this action on the
clusterresource can enable or disable Free Monitoring.New in version 4.0.
Diagnostic Actions
collStats-
User can perform the
collStatscommand. Apply this action to database or collection resources.
connPoolStats-
User can perform the
connPoolStatscommand. Apply this action to theclusterresource.
dbHash-
User can perform the
dbHashcommand. Apply this action to database or collection resources.
dbStats-
User can perform the
dbStatscommand. Apply this action to database resources.
getCmdLineOpts-
User can perform the
getCmdLineOptscommand. Apply this action to theclusterresource.
getLog-
User can perform the
getLogcommand. Apply this action to theclusterresource.
indexStats-
User can perform the
indexStatscommand. Apply this action to database or collection resources.Changed in version 3.0: MongoDB 3.0 removes the
indexStatscommand.
listDatabases-
User can perform the
listDatabasescommand. Apply this action to theclusterresource.If the user does not have the
listDatabasesprivilege action, users can run thelistDatabasescommand 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 withauthorizedDatabasesoption unspecified or set totrue.
listCollections-
User can perform the
listCollectionscommand. Apply this action to database resources.Note
Starting in version 4.0, user without the required privilege can run the
listCollectionscommand with bothauthorizedCollectionsandnameOnlyoptions set totrue. In this case, the command returns just the name and type of the collection(s) to which the user has privileges.
listIndexes-
User can perform the
listIndexescommand. Apply this action to database or collection resources.
netstat-
User can perform the
netstatcommand. Apply this action to theclusterresource.
serverStatus-
User can perform the
serverStatuscommand. Apply this action to theclusterresource.
validate-
User can perform the
validateandvalidateDBMetadatacommands. Apply this action to database or collection resources.
top-
User can perform the
topcommand. Apply this action to theclusterresource.
Internal Actions
anyAction-
Allows any action on a resource. Do not assign this action unless it is absolutely necessary.
applyOps-
User can perform the
applyOpscommand. Apply this action to aclusterresource.