我正在尝试创建一个用户角色,该角色可以在 MongoDB 上设置分析级别以执行慢速查询检查。
角色:
db.createRole(
{
role: "slow_query_check",
privileges: [
{ resource: { db: "admin", collection: "system.profile"}, actions: [ "enableProfiler" ] },
],
roles: [
{ role: "read", db: "admin" }
]
},
{ w: "majority" , wtimeout: 5000 }
)
然后我正在应用这个角色:
db.grantRolesToUser(
"monitor",
[
{ role: "slow_query_check", db: "admin" },
]
)
但我仍然无法设置例如。db.setProfilingLevel(0) 因为我未经授权。
根据手册: https ://docs.mongodb.com/v4.2/reference/privilege-actions/
enableProfiler是我需要授予的操作,但这不起作用。
有什么帮助吗?