Privilege Actions
New in version 2.6.
Privilege actions define the operations a user can perform on a resource. A MongoDB privilege comprises aresource and the permitted actions. This page listsavailable actions grouped by common purpose.
MongoDB provides built-in roles with pre-defined pairings of resources andpermitted actions. For lists of the actions granted, seeBuilt-In Roles. To define custom roles, seeCreate a User-Defined Role.
Query and Write Actions
find
User can perform the following commands, and their equivalent helper methods:
aggregate
for all pipeline operationsexcept$collStats
,$out
, and$indexStats
.checkShardingIndex
count
dataSize
distinct
filemd5
find
geoSearch
getLastError
getMore
getPrevError
killCursors
, provided that the cursor is associatedwith a currently authenticated user.listCollections
listIndexes
mapReduce
with the{out: inline}
option.repairCursor
resetError
Required for the query portion of themapReduce
command anddb.collection.mapReduce
helper method when outputtingto a collection.
Required for the query portion of the findAndModify
commandand db.collection.findAndModify
helper method.
Required on the source collection for the cloneCollectionAsCapped
and renameCollection
commands and thedb.collection.renameCollection()
helper method.
- For MongoDB 4.0.6+:
- If the user does not have the
listDatabases
privilege action, users can run thelistDatabases
command to return a list of databases for which the user hasprivileges (including databases for which the user has privilegeson specific collections) if the command is run withauthorizedDatabases
option unspecified or set totrue
. - For MongoDB 4.0.5:
- If the user does not have the
listDatabases
privilege action, users can run thelistDatabases
command to return a list of databases for which the user has thefind
action privilege if the command is run withauthorizedDatabases
option unspecified or set totrue
. - For MongoDB 4.0.0-4.0.4:
- If the user does not have the
listDatabases
privilege action, users can run thelistDatabases
command to return a list of databases for which the user has thefind
action privilege.Apply this action to database or collection resources.
insert
User can perform the following commands and their equivalent methods:
insert
create
Required for the output portion of themapReduce
command anddb.collection.mapReduce()
helper method whenoutputting to a collection.
Required for the aggregate
command anddb.collection.aggregate()
helper method when using the$out
pipeline operator.
Required for the update
and findAndModify
commands and equivalent helper methods when used with the upsert
option.
Required on the destination collection for the followingcommands and their helper methods:
cloneCollection
cloneCollectionAsCapped
renameCollection
Apply this action to database or collection resources.
remove
- User can perform the
delete
command and equivalenthelper method.
Required for the write portion of the findAndModify
command and db.collection.findAndModify()
method.
Required for the mapReduce
command anddb.collection.mapReduce()
helper method when you specifythe replace
action when outputting to a collection.
Required for the aggregate
command anddb.collection.aggregate()
helper method when using the$out
pipeline operator.
Apply this action to database or collection resources.
update
- User can perform the
update
command and equivalenthelper methods.
Required for themapReduce
command and db.collection.mapReduce()
helper method when outputting to a collectionwithout specifying the replace
action.
Required for the findAndModify
command anddb.collection.findAndModify()
helper method.
Apply this action to database or collection resources.
New in version 3.2.
Users can bypass document validation on commands and methods that supportthe bypassDocumentValidation
option. The following commands andtheir equivalent methods support bypassing document validation:
aggregate
applyOps
cloneCollection
on the destination collectionfindAndModify
insert
mapReduce
update
Apply this action to database or collection resources.
New in version 3.6.
User can execute the following commands using aUUID as if it were anamespace:
find
listIndexes
For example, this privilege authorizes a user to run thefollowing command which executes afind
command on acollection with the given UUID. In order to be successful, thisoperation also requires that the user is authorized to execute thefind
command on the collection namespace corresponding to the givenUUID.
- db.runCommand({find: UUID("123e4567-e89b-12d3-a456-426655440000")})
For more information on collection UUIDs, seeCollections.
Apply this action to the cluster
resource.
Database Management Actions
changeCustomData
- User can change the custom information of any user in the givendatabase. Apply this action to database resources.
changeOwnCustomData
- Users can change their own custom information. Apply this action todatabase resources. See alsoChange Your Password and Custom Data.
changeOwnPassword
- Users can change their own passwords. Apply this action to databaseresources. See alsoChange Your Password and Custom Data.
changePassword
- User can change the password of any user in the given database. Applythis action to database resources.
createCollection
- User can perform the
db.createCollection()
method. Apply thisaction to database or collection resources.
createIndex
- Provides access to the
db.collection.createIndex()
methodand thecreateIndexes
command.Apply this action to database or collection resources.
dropCollection
- User can perform the
db.collection.drop()
method. Apply thisaction to database or collection resources.
enableProfiler
- User can perform the
db.setProfilingLevel()
method. Applythis action to database resources.
grantRole
- User can grant any role in the database to any user from any databasein 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, thekillCursors
privilege has no effect in MongoDB 4.2+.
In MongoDB 3.6.3 through MongoDB 4.0.x, users requirekillCursors
privilege to kill their own curors whenaccess control is enabled. Cursors are associated with the users atthe time of cursor creation. Apply this action to collectionresources.
New in version 3.6.3.
User can kill any cursor, even cursors created by other users.Apply this action to collection resources.
revokeRole
- User can remove any role from any user from any database in the system.Apply this action to database resources.
New in version 3.6.
User can specify theauthenticationRestrictionsfield in the user
document when running the following commands:
- createUser
updateUserUser can specify the
authenticationRestrictions
field in therole
document when running the following commands:- updateRole
Note
The following built-in roles grant this privilege:
- The
userAdmin
role provides this privilegeon the database that the role is assigned. - The
userAdminAnyDatabase
role provides thisprivilege on all databases.Transitively, therestore
androot
rolesalso provide this privilege.
Apply this action to database resources.
unlock
- User can perform the
db.fsyncUnlock()
method. Apply thisaction to thecluster
resource.
viewRole
- User can view information about any role in the given database. Applythis action to database resources.
viewUser
- User can view the information of any user in the given database. Applythis action to database resources.
Deployment Management Actions
authSchemaUpgrade
- User can perform the
authSchemaUpgrade
command. Apply thisaction to thecluster
resource.
cleanupOrphaned
- User can perform the
cleanupOrphaned
command. Apply thisaction to thecluster
resource.
inprog
- User can use the
db.currentOp()
method to returninformation on pending and active operations. Apply this action tothecluster
resource.
Changed in version 3.2.9: Even without the inprog
privilege, onmongod
instances, users can view their own operationsby running db.currentOp( { "$ownOps": true } )
.
invalidateUserCache
- Provides access to the
invalidateUserCache
command. Applythis action to thecluster
resource.
killop
- User can perform the
db.killOp()
method. Apply this action tothecluster
resource.
Changed in version 3.2.9: Even without the killop
privilege, onmongod
instances, users can killtheir own operations.
planCacheRead
User can run the following operations:
$planCacheStats
aggregation stage.planCacheListPlans
command andPlanCache.getPlansByQuery()
method.planCacheListQueryShapes
command and thePlanCache.listQueryShapes()
method.Apply this action to database or collection resources.
planCacheWrite
- User can perform the
planCacheClear
command and thePlanCache.clear()
andPlanCache.clearPlansByQuery()
methods. Apply this action to database or collection resources.
storageDetails
- User can perform the
storageDetails
command. Apply thisaction to database or collection resources.
Change Stream Actions
changeStream
- User with
changeStream
andfind
on thespecific collection, all non-system
collections in aspecifc database, or all non-system
collections across all databases canopen change stream cursor for that resource.
Replication Actions
replSetGetConfig
- User can view a replica set’s configuration. Provides access to the
replSetGetConfig
command andrs.conf()
helpermethod.
Apply this action to the cluster
resource.
replSetGetStatus
- User can perform the
replSetGetStatus
command. Apply thisaction to thecluster
resource.
replSetHeartbeat
- User can perform the
replSetHeartbeat
command. Apply thisaction to thecluster
resource.
replSetStateChange
- User can change the state of a replica set through the
replSetFreeze
,replSetMaintenance
,replSetStepDown
, andreplSetSyncFrom
commands. Apply this action to thecluster
resource.
Sharding Actions
addShard
- User can perform the
addShard
command. Apply this actionto thecluster
resource.
enableSharding
- User can enable sharding on a database using the
enableSharding
command and can shard a collection usingtheshardCollection
command. Apply this action todatabase or collection resources.
flushRouterConfig
- User can perform the
flushRouterConfig
command. Apply thisaction to thecluster
resource.
getShardMap
- User can perform the
getShardMap
command. Apply this actionto thecluster
resource.
getShardVersion
- User can perform the
getShardVersion
command. Apply thisaction to database resources.
listShards
- User can perform the
listShards
command. Apply this actionto thecluster
resource.
moveChunk
- User can perform the
moveChunk
command. In addition, usercan perform themovePrimary
command provided that the privilegeis applied to an appropriate database resource. Apply this action to databaseor collection resources.
removeShard
- User can perform the
removeShard
command. Apply thisaction to thecluster
resource.
shardingState
- User can perform the
shardingState
command. Apply thisaction to thecluster
resource.
splitChunk
- User can perform the
splitChunk
command and themergeChunks
command. Apply this action to database orcollection resources.
splitVector
- User can perform the
splitVector
command. Apply this action todatabase or collection resources.
Server Administration Actions
applicationMessage
- User can perform the
logApplicationMessage
command. Applythis action to thecluster
resource.
closeAllDatabases
- User can perform the
closeAllDatabases
command. Apply thisaction to thecluster
resource.
collMod
- User can perform the
collMod
command. Apply this action todatabase or collection resources.
compact
- User can perform the
compact
command. Apply this action todatabase or collection resources.
connPoolSync
- User can perform the
connPoolSync
command. Apply thisaction to thecluster
resource.
convertToCapped
- User can perform the
convertToCapped
command. Apply thisaction to database or collection resources.
dropConnections
- User can perform the
dropConnections
command. Apply thisaction to thecluster
resource.
dropDatabase
- User can perform the
dropDatabase
command. Apply this actionto database resources.
dropIndex
- User can perform the
dropIndexes
command. Apply this actionto database or collection resources.
New in version 3.6.
User can create a collection with a user-definedcollection UUID using theapplyOps
command.
Apply this action to the cluster
resource.
fsync
- User can perform the
fsync
command. Apply this action tothecluster
resource.
getParameter
- User can perform the
getParameter
command. Apply thisaction to thecluster
resource.
hostInfo
- Provides information about the server the MongoDB instance runs on. Applythis action to the
cluster
resource.
logRotate
- User can perform the
logRotate
command. Apply this actionto thecluster
resource.
reIndex
- User can perform the
reIndex
command. Apply this action todatabase or collection resources.
renameCollectionSameDB
- Allows the user to rename collections on the current database using the
renameCollection
command. Apply this action to databaseresources.
Additionally, the user must either havefind
on thesource collection or not havefind
on the destinationcollection.
If a collection with the new name already exists, the user must alsohave the dropCollection
action on the destinationcollection.
setParameter
- User can perform the
setParameter
command. Apply thisaction to thecluster
resource.
shutdown
- User can perform the
shutdown
command. Apply this actionto thecluster
resource.
Session Actions
New in version 3.6.
User can perform the killAllSessionsByPattern
commandwith users
and roles
pattern. Apply this action to thecluster
resource.
To run killAllSessionsByPattern
command, users mustalso have killAnySession
privileges on the clusterresource.
New in version 3.6.
User can perform the $listSessions
operation or$listLocalSessions
operation for all users or specifieduser(s). Apply this action to the cluster
resource.
New in version 3.6.
User can perform the killAllSessions
and thekillAllSessionsByPattern
command. Apply this action tothe cluster
resource.
See also
Free Monitoring Actions
checkFreeMonitoringStatus
- User with this action on the
cluster
resource can check thestatus of Free Monitoring.
New in version 4.0.
setFreeMonitoring
- User with this action on the
cluster
resource can enable ordisable Free Monitoring.
New in version 4.0.
Diagnostic Actions
collStats
- User can perform the
collStats
command. Apply this actionto database or collection resources.
connPoolStats
- User can perform the
connPoolStats
andshardConnPoolStats
commands. Apply this action to thecluster
resource.
cursorInfo
- User can perform the
cursorInfo
command. Apply this actionto thecluster
resource.
dbHash
- User can perform the
dbHash
command. Apply this action todatabase or collection resources.
dbStats
- User can perform the
dbStats
command. Apply this action todatabase resources.
getCmdLineOpts
- User can perform the
getCmdLineOpts
command. Apply thisaction to thecluster
resource.
getLog
- User can perform the
getLog
command. Apply this action tothecluster
resource.
indexStats
- User can perform the
indexStats
command. Apply this actionto database or collection resources.
Changed in version 3.0: MongoDB 3.0 removes the indexStats
command.
listDatabases
User can perform the
listDatabases
command. Apply thisaction to thecluster
resource.- For MongoDB 4.0.6+:
- If the user does not have the
listDatabases
privilege action, users can run thelistDatabases
command to return a list of databases for which the user hasprivileges (including databases for which the user has privilegeson specific collections) if the command is run withauthorizedDatabases
option unspecified or set totrue
. - For MongoDB 4.0.5:
- If the user does not have the
listDatabases
privilege action, users can run thelistDatabases
command to return a list of databases for which the user has thefind
action privilege if the command is run withauthorizedDatabases
option unspecified or set totrue
. - For MongoDB 4.0.0-4.0.4:
- If the user does not have the
listDatabases
privilege action, users can run thelistDatabases
command to return a list of databases for which the user has thefind
action privilege.
listCollections
- User can perform the
listCollections
command. Apply thisaction to database resources.
Note
Starting in version 4.0, user without the required privilege canrun the listCollections
command with bothauthorizedCollections
and nameOnly
options set totrue
. In this case, the command returns just the name andtype of the collection(s) to which the user has privileges.
listIndexes
- User can perform the
listIndexes
command. Apply thisaction to database or collection resources.
netstat
- User can perform the
netstat
command. Apply this action tothecluster
resource.
serverStatus
- User can perform the
serverStatus
command. Apply this actionto thecluster
resource.
validate
- User can perform the
validate
command. Apply this actionto database or collection resources.
top
- User can perform the
top
command. Apply this action to thecluster
resource.