特权操作定义了用户可以对资源执行的操作。MongoDB 特权包括资源和允许的操作。此页面列出了按常见用途分组的可用操作。
MongoDB 可提供内置角色以及“资源与允许操作”的预定义对。有关已授予的操作列表,请参阅:
要定义自定义角色,请参阅:
查询和写入操作
find用户可以执行以下命令及其等效辅助方法:
killCursors,前提是游标与当前经过身份验证的用户关联mapReduce和{out: inline}选项
输出至集合时,
mapReduce命令和db.collection.mapReduce()辅助方法的查询部分为必填项。findAndModify命令和db.collection.findAndModify()辅助方法的查询部分为必填项。cloneCollectionAsCapped和renameCollection命令以及db.collection.renameCollection()辅助方法的源集合为必填项。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.将此操作应用于数据库或集合资源。
insert用户可执行以下命令及其等效方法:
输出至集合时,
mapReduce命令和db.collection.mapReduce()辅助方法的输出部分为必填项。使用
$out或$merge管道操作符时,aggregate命令和db.collection.aggregate()辅助方法为必填项。与
upsert选项一起使用时,update和findAndModify命令以及等效辅助方法为必填项。以下命令及其辅助方法的目标集合为必填项:
将此操作应用于数据库或集合资源。
remove用户可以执行
delete命令和等效的辅助方法。findAndModify命令和db.collection.findAndModify(){5} 方法的写入部分为必填项。指定
replace操作时,mapReduce命令和db.collection.mapReduce()辅助方法为必填项,输出到集合时。使用
$out管道操作符时,aggregate命令和db.collection.aggregate()辅助方法为必填项。将此操作应用于数据库或集合资源。
update用户可以执行
update命令和等效的辅助方法。在未指定
replace操作的情况下输出至集合时,mapReduce命令和db.collection.mapReduce()辅助方法为必填项。findAndModify命令和db.collection.findAndModify()辅助方法为必填项。将此操作应用于数据库或集合资源。
bypassDocumentValidation对于支持
bypassDocumentValidation选项的命令和方法,用户可绕过模式验证。以下命令及其等效方法支持绕过模式验证:将此操作应用于数据库或集合资源。
数据库管理操作
changeOwnCustomData用户可以更改自己的自定义信息。将此操作应用于数据库资源。另请参阅更改密码和自定义数据。
changeOwnPassword用户可以更改自己的密码。将此操作应用于数据库资源。另请参阅更改密码和自定义数据。
createCollection用户可以执行
db.createCollection()方法。将此操作应用于数据库或集合资源。
createIndex提供对
db.collection.createIndex()方法和createIndexes命令的访问权限。将此操作应用于数据库或集合资源。
dropCollection用户可以执行
db.collection.drop()方法。将此操作应用于数据库或集合资源。
enableProfiler用户可以执行
db.setProfilingLevel()方法。将此操作应用于数据库资源。
planCacheIndexFilterUser can run the
planCacheClearFilters,planCacheListFilters, andplanCacheSetFiltercommands. Apply theplanCacheIndexFilteraction to collection resources.
querySettings用户可以运行
setQuerySettings和removeQuerySettings命令,并为聚合管道添加$querySettings阶段。8.0版本新增。
setAuthenticationRestriction运行以下命令时,用户可以在
user文档中指定 authenticationRestrictions 字段:运行以下命令时,用户可以在
role文档中指定authenticationRestrictions字段:将此操作应用于数据库资源。
setFeatureCompatibilityVersion用户可以运行
setFeatureCompatibilityVersion命令。将此操作应用于cluster资源。
unlock用户可以执行
db.fsyncUnlock()方法。将此操作应用于cluster资源。
部署管理操作
inprog用户可使用
db.currentOp()方法返回待执行和活动操作的信息。将此操作应用于cluster资源。Even without the
inprogprivilege, onmongodinstances, users can view their own operations by runningdb.currentOp( { "$ownOps": true } ).
invalidateUserCache提供对
invalidateUserCache命令的访问权限。将此操作应用于cluster资源。
killop用户可以执行
db.killOp()方法。将此操作应用于cluster资源。Even without the
killopprivilege, onmongodinstances, users can kill their own operations.
planCacheRead用户可以运行以下操作:
$planCacheStats聚合阶段
将此操作应用于数据库或集合资源。
planCacheWrite用户可以执行
planCacheClear命令以及PlanCache.clear()和PlanCache.clearPlansByQuery()方法。将此操作应用于数据库或集合资源。
变更流操作
changeStreamUser 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.
复制操作
replSetGetConfig用户可以查看副本集的配置。提供对
replSetGetConfig命令和rs.conf()辅助方法的访问权限。将此操作应用于
cluster资源。
replSetGetStatus用户可以执行
replSetGetStatus命令。将此操作应用于cluster资源。
replSetStateChange用户可以通过
replSetFreeze、replSetMaintenance、replSetStepDown和replSetSyncFrom命令更改副本集的状态。将此操作应用于cluster资源。
分片操作
addShard用户可以执行
addShard命令。将此操作应用于cluster资源。
analyzeShardKey用户可以执行
analyzeShardKey命令。将此动作应用于数据库和集合资源。包含在
clusterManager和enableSharding内置角色中。
checkMetadataConsistency用户可以执行
checkMetadataConsistency命令。将此操作应用于cluster、数据库或集合资源。7.0版本新增。
clearJumboFlag需要使用
clearJumboFlag命令清除数据段的巨型标志。将此操作应用于数据库或集合资源。包含在
clusterManager内置角色中。
enableSharding- 资源说明
授予用户执行以下操作的特权:
使用
enableSharding命令在数据库上启用分片使用
shardCollection命令对集合进行分片
refineCollectionShardKey提供优化分片集合的分片键并运行
refineCollectionShardKey命令的特权。将此操作应用于数据库或集合资源。包含在
clusterManager内置角色中。
moveCollection用户可以执行
moveCollection命令。将此操作应用于cluster资源。8.0版本新增。
reshardCollection用户可以执行
reshardCollection命令。将此操作应用于数据库或集合资源。版本 5.0 中的新增功能。
rewriteCollection用户可以执行
rewriteCollection和abortRewriteCollection命令。将此操作应用到数据库或集合资源。8.3版本新增。
unshardCollection用户可以执行
unshardCollection命令。将此操作应用于cluster资源。8.0版本新增。
flushRouterConfig用户可以执行
flushRouterConfig命令。将此操作应用于cluster资源。
getClusterParameter用户可以执行
getClusterParameter命令。将此操作应用于cluster资源。6.0版本新增。
getShardMap用户可以执行
getShardMap命令。将此操作应用于cluster资源。
listShards用户可以执行
listShards命令。将此操作应用于cluster资源。
moveChunk用户可以执行
moveChunk和moveRange命令。此外,只要特权应用于适当的数据库资源,用户还可以执行movePrimary命令。将此操作应用于数据库或集合资源。
removeShard用户可以执行
removeShard命令。将此操作应用于cluster资源。
shardedDataDistribution用户可以执行
$shardedDataDistribution聚合管道阶段。6.0.3版本新增。
shardingState用户可以执行
shardingState命令。将此操作应用于cluster资源。
splitChunk用户可以执行
split命令。将此操作应用于cluster资源。
transitionFromDedicatedConfigServer对
cluster资源执行此操作的用户可以运行transitionFromDedicatedConfigServer命令。8.0版本新增。
transitionToDedicatedConfigServer对
cluster资源执行此操作的用户可以运行transitionToDedicatedConfigServer命令。8.0版本新增。
服务器管理操作
applicationMessage用户可以执行
logApplicationMessage命令。将此操作应用于cluster资源。
bypassWriteBlockingMode即使在
setUserWriteBlockMode命令阻止写入时,用户也可以执行写入操作。将此操作应用于cluster资源。
bypassDefaultMaxTimeMS用户运行的所有查询都会忽略
defaultMaxTimeMS参数的值。8.0版本新增。
collMod用户可以执行
collMod命令。将此操作应用于数据库或集合资源。
compact用户可以执行
compact命令。将此操作应用于数据库或集合资源。在自管理部署中,您还需要在集群资源上执行
compact权限操作才能运行autoCompact命令。有关每种部署类型所需权限,请参阅 所需权限。
compactStructuredEncryptionData用户可以执行
compactStructuredEncryptionData命令。将此操作应用于数据库资源。注意
已在版本 9.0:(以及 8.3.8、8.2.13、8.0.29、7.0.40)
此操作仅适用于数据库资源。在早期版本中,您还可以将此操作应用于集合资源。
convertToCapped用户可以执行
convertToCapped命令。将此操作应用于数据库或集合资源。
dropConnections用户可以执行
dropConnections命令。将此操作应用于cluster资源。
dropDatabase用户可以执行
dropDatabase命令。将此操作应用于数据库资源。
dropIndex用户可以执行
dropIndexes命令。将此操作应用于数据库或集合资源。
fsync用户可以执行
fsync命令。将此操作应用于cluster资源。
getDefaultRWConcern用户可以发出管理
getDefaultRWConcern命令。将此操作应用于cluster资源。
getParameter用户可以执行
getParameter命令。将此操作应用于cluster资源。
oidReset需要重置对象标识符中使用的 5 字节随机字符串。
logRotate用户可以执行
logRotate命令。将此操作应用于cluster资源。
reIndex用户可以执行
reIndex命令。将此操作应用于数据库或集合资源。
renameCollectionSameDB允许用户使用
renameCollection命令重命名当前数据库上的集合。将此操作应用于数据库资源。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用户可以执行
rotateCertificates命令。将此操作应用于cluster资源。
setDefaultRWConcern用户可以发出管理
setDefaultRWConcern命令。将此操作应用于cluster资源。
setParameter用户可以执行
setParameter命令。将此操作应用于cluster资源。
setUserWriteBlockMode用户可以执行
setUserWriteBlockMode命令。将此操作应用于cluster资源。
shutdown用户可以执行
shutdown命令。将此操作应用于cluster资源。
会话操作
impersonate用户可以使用
users和roles模式执行killAllSessionsByPattern命令。将此操作应用于cluster资源。To run
killAllSessionsByPatterncommand, users must also havekillAnySessionprivileges on the cluster resource.
listSessions用户可以为所有用户或指定用户执行
$listSessions操作或$listLocalSessions操作。将此操作应用于cluster资源。
killAnySession用户可以执行
killAllSessions和killAllSessionsByPattern命令。将此操作应用于cluster资源。
MongoDB Search 索引操作
以下操作启用用户能够运行MongoDB搜索数据库命令。这些操作仅与MongoDB Atlas上托管的部署相关。
createSearchIndexes用户可以运行
createSearchIndexes数据库命令。将此动作应用于数据库、集合或视图资源。
dropSearchIndex用户可以运行
dropSearchIndex数据库命令。将此动作应用于数据库、集合或视图资源。
listSearchIndexes用户可以运行
$listSearchIndexes聚合阶段。将此动作应用于数据库、集合或视图资源。
updateSearchIndex用户可以运行
updateSearchIndex数据库命令。将此动作应用于数据库、集合或视图资源。
诊断操作
collStats用户可以执行
collStats命令。将此操作应用于数据库或集合资源。
connPoolStats用户可以执行
connPoolStats命令。将此操作应用于cluster资源。
dbHash用户可以执行
dbHash命令。将此操作应用于数据库或集合资源。
dbStats用户可以执行
dbStats命令。将此操作应用于数据库资源。
getCmdLineOpts用户可以执行
getCmdLineOpts命令。将此操作应用于cluster资源。
getLog用户可以执行
getLog命令。将此操作应用于cluster资源。
indexStats用户可以运行
$indexStats聚合管道阶段。将此操作应用于数据库或集合资源。要使用
$indexStats阶段,用户必须至少使用clusterMonitor角色进行身份验证。
listClusterCatalog用户可以在
admin数据库上运行$listClusterCatalog聚合管道阶段。要在admin数据库上运行$listClusterCatalog,用户必须使用clusterMonitor角色进行身份验证。
listDatabases用户可以执行
listDatabases命令。将此操作应用于cluster资源。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.
listCollections用户可以执行
listCollections命令。将此操作应用于数据库资源。注意
没有所需权限的用户可以运行
listCollections命令,并将authorizedCollections和nameOnly选项设置为true。在此情况下,该命令仅返回用户拥有特权的集合的名称和类型。
listIndexes用户可以执行
listIndexes命令。将此操作应用于数据库或集合资源。
queryStatsRead用户可以在没有
transformIdentifiers选项的情况下运行$queryStats聚合阶段。
queryStatsReadTransformed用户可以在使用或不使用
transformIdentifiers选项的情况下运行$queryStats聚合阶段。
serverStatus用户可以执行
serverStatus命令。将此操作应用于cluster资源。
validate用户可以执行
validate和validateDBMetadata命令。将此操作应用于数据库或集合资源。
top用户可以执行
top命令。将此操作应用于cluster资源。
内部操作
applyOps用户可以执行
applyOps命令。将此操作应用于cluster资源。