mongob用户权限管理
//查询所有角色权限
db.runCommand({rolesInfo:1})
//查询所有角色权限(包含内置角色)
db.runCommand({rolesInfo:1,showBuiltinRoles:true})
//查询当前数据库中某角色的权限
db.runCommand({rolesInfo:""})
//查询其他数据库中某角色的权限
db.runCommand({role:"",db:""})
db.runCommand({rolesInfo:[
"<rolename>",
{role:"",db:""}
...
]})
db.runCommand({rolesInfo:1,showBuiltinRoles:true})
{
"roles" : [
{
"role" : "dbAdmin",
"db" : "test",
"isBuiltin" : true,
"roles" : [ ],
"inheritedRoles" : [ ]
},
{
"role" : "dbOwner",
"db" : "test",
"isBuiltin" : true,
"roles" : [ ],
"inheritedRoles" : [ ]
},
{
"role" : "enableSharding",
"db" : "test",
"isBuiltin" : true,
"roles" : [ ],
"inheritedRoles" : [ ]
},
{
"role" : "read",
"db" : "test",
"isBuiltin" : true,
"roles" : [ ],
"inheritedRoles" : [ ]
},
{
"role" : "readWrite",
"db" : "test",
"isBuiltin" : true,
"roles" : [ ],
"inheritedRoles" : [ ]
},
{
"role" : "userAdmin",
"db" : "test",
"isBuiltin" : true,
"roles" : [ ],
"inheritedRoles" : [ ]
}
],
"ok" : 1
}
创建超级用户:
>use admin
>db.createUser({user:"yuanqiao",pwd:"123456",roles:["root"]})
>db.createUser({user:"myadmin",pwd:"123456",roles:[{"role":"userAdminAnyDatabase","db":"admin"}]})
>show collections
>db.system.users.find()
//删除用户
>db.dropUser("myadmin")
>db.changeUserPassword("yuanqiao","654321")
>db.auth("yuanqiao","123456")
> use aticledb
>db.createUser({user:"bobo",pwd:"123456",roles:[{"role":"read","db":"aticledb"}]})
mongodb://localhost:27017/?readPreference=primary&appname=MongoDB%20Compass&ssl=false