MongoDB 4.0檢視,更新和回收角色許可權步驟
檢視角色許可權資訊:
use admin
> db.system.roles.find().pretty()
{
"_id" : "admin.custom_role_test",
"role" : "custom_role_test",
"db" : "admin",
"privileges" : [
{
"resource" : {
"db" : "test",
"collection" : " "
},
"actions" : [
"createCollection",
"createIndex",
"find",
"insert",
"update"
]
}
],
"roles" : [
{
"role" : "read",
"db" : "test"
}
]
}
{
"_id" : "test.custom_role_test",
"role" : "custom_role_test",
"db" : "test",
"privileges" : [
{
"resource" : {
"db" : "test",
"collection" : " "
},
"actions" : [
"createCollection",
"createIndex",
"find",
"insert",
"update"
]
}
],
"roles" : [
{
"role" : "read",
"db" : "test"
}
]
}
檢視使用者:
PRIMARY> show users
{
"_id" : "admin.test_rw",
"userId" : UUID("7cd05387-fb0c-49b3-9c04-49b8444e8d6f"),
"user" : "test_rw",
"db" : "admin",
"roles" : [
{
"role" : "custom_role_test",
"db" : "test"
}
],
"mechanisms" : [
"SCRAM-SHA-1",
"SCRAM-SHA-256"
]
}
{
"_id" : "admin.root",
"userId" : UUID("9416402a-d029-4add-8d0b-66b65b9f5a94"),
"user" : "root",
"db" : "admin",
"roles" : [
{
"role" : "root",
"db" : "admin"
}
],
"mechanisms" : [
"SCRAM-SHA-1",
"SCRAM-SHA-256"
]
}
檢視使用者資訊:
PRIMARY> db.runCommand({usersInfo:"test_rw"})
{
"users" : [
{
"_id" : "admin.test_rw",
"userId" : UUID("7cd05387-fb0c-49b3-9c04-49b8444e8d6f"),
"user" : "test_rw",
"db" : "admin",
"roles" : [
{
"role" : "custom_role_customer",
"db" : "customer"
},
{
"role" : "custom_role_test",
"db" : "test"
}
],
"mechanisms" : [
"SCRAM-SHA-1",
"SCRAM-SHA-256"
]
}
],
"ok" : 1,
"$clusterTime" : {
"clusterTime" : Timestamp(1654076841, 1),
"signature" : {
"hash" : BinData(0,"8JWM/9Xy+h9L/7L/6vIMsQUz8ug="),
"keyId" : NumberLong("7066856411933704193")
}
},
"operationTime" : Timestamp(1654076841, 1)
}
更新角色許可權資訊:
語法:
db.updateRole(
"<rolename>",
{
privileges:
[
{ resource: { <resource> }, actions: [ "<action>", ... ] },
...
],
roles:
[
{ role: "<role>", db: "<database>" } | "<role>",
...
]
},
{ <writeConcern> }
)
例子(修改許可權資訊,加入remove許可權):
use admin
db.updateRole(
"custom_role_test",
{
privileges:
[
{
resource: { db:"test", collection:" " },
actions: [ "insert", "update", "find" ,"remove","createCollection", "createIndex"]
}
],
roles:
[
{
role: "read",
db: "test"
}
]
},
{ w:"majority" }
);
use test
db.updateRole(
"custom_role_test",
{
privileges:
[
{
resource: { db:"test", collection:" " },
actions: [ "insert", "update", "find","remove" ,"createCollection", "createIndex"]
}
],
roles:
[
{
role: "read",
db: "test"
}
]
},
{ w:"majority" }
);
回收角色許可權步驟:
語法:
db.revokeRolesFromUser( "<username>", [ <roles> ], { <writeConcern> } )
例子:
use test
db.revokeRolesFromUser( "test",
[ { role: "read", db: "test" }, "readWrite" ],
{ w: "majority" }
)
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/15498/viewspace-2898625/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- MongoDB4.0建立自定義許可權(只有查詢,插入和更新的許可權)的角色步驟MongoDB
- 檢視角色裡包含的系統許可權、物件許可權和角色物件
- 檢視Oracle使用者的許可權或角色Oracle
- Oracle角色、許可權的一些常用檢視Oracle
- 【許可權管理】Oracle中檢視、回收使用者許可權Oracle
- Oracle檢視許可權Oracle
- 如何檢視oracle使用者具有的許可權和角色Oracle
- Oracle的物件許可權、角色許可權、系統許可權Oracle物件
- 查詢資料庫使用者角色和許可權檢視資料庫
- 如何用 Vue 實現前端許可權控制(路由許可權 + 檢視許可權 + 請求許可權)Vue前端路由
- 許可權授予、回收命令
- 物件許可權的回收物件
- Oracle檢視當前登陸使用者的許可權或者角色Oracle
- oracle許可權相關檢視Oracle
- 使用者有connect,resource,dba角色許可權後回收dba許可權導致無UNLIMITED TABLESPACE許可權造成業務中斷MIT
- Oracle檢視使用者預設表空間、臨時表空間、系統許可權、物件許可權、角色許可權舉例說明Oracle物件
- MongoDB 3.2的使用者角色許可權介紹和配置MongoDB
- Oracle 查詢許可權角色Oracle
- Oracle許可權(二)許可權相關的動態效能檢視與資料字典檢視Oracle
- MongoDB 3.0.8 許可權管理MongoDB
- linux檢視檔案許可權Linux
- Oracle檢視使用者許可權Oracle
- 檢視oracle 使用者許可權Oracle
- 檢視許可權的設定案例
- Oracle中使用者、角色、與許可權涉及的相關表及檢視Oracle
- Oracle角色許可權之Default RoleOracle
- Java Web角色許可權設計JavaWeb
- Swift4.0 訪問許可權Swift訪問許可權
- 擁有GRANT ANY OBJECT PRIVILEGE許可權時的許可權回收Object
- mongodb 的許可權系統MongoDB
- 如何檢視postgresql使用者許可權SQL
- oracle的儲存許可權的檢視Oracle
- Oracle使用者角色許可權管理Oracle
- 系統,物件,角色許可權簡析物件
- Oracle使用者、許可權、角色管理Oracle
- MySQL5.7&8.0許可權-角色管理MySql
- oracle受權與回收許可權grant和revokeOracle
- unlimited tablespace許可權的授予和回收MIT