大家好,我是考100分的小小码 ,祝大家学习进步,加薪顺利呀。今天说一说MongoDB用户相关[通俗易懂],希望您对编程的造诣更进一步.
2.可以优先创建标红的MongoDB用户
3.创建用户命令列表
创建用户一定要在具体的db下执行
use admin
Root用户:
db.createUser({user:"root", pwd:“pwd", roles:[{role:"root", db:"admin"}]})(一般不要用这个用户)
仅次于ROOT用户的:
db.createUser({ user:"admin",pwd:"pwd",
roles:[
{role:"clusterAdmin",db:"admin"},
{role:"userAdminAnyDatabase",db:"admin"},
{role:"dbAdminAnyDatabase",db:"admin"},
{role:"readWriteAnyDatabase",db:"admin"}
]})
门管理用户的:
db.createUser({user:"userAdmin", pwd:“pwd", roles:[{role:"userAdminAnyDatabase", db:"admin"}]})
备份用户的:
db.createUser({user:"backup", pwd:" pwd ", roles:[{role:"backup", db:"admin"}]})
恢复用户:
db.createRole({role:"restoreEx", ,privileges:[{resource:{anyResource:true},actions:["anyAction"]}],roles:[{role:"restore", db:"admin"}]})(这个权限开的太大了)
db.createRole({role:‘restoreEx’, ,privileges:[{resource:{db:“config”,collection:“system.sessions”},actions:[‘find’,‘insert’,‘remove’,‘update’]}],roles:[{role:“restore”, db:“admin”}]})(优先这个)
db.adminCommand({ createRole: "restoreEx", privileges: [ { resource: { db: "config", collection: "system.sessions" }, actions: [ "find", "update", "insert", "remove" ] }, ], roles: [ { role: "restore", db: "admin" } ], writeConcern: { w: "majority" , wtimeout: 5000 }})
删除用户:
db.dropUser(“xxx”);
删除角色:
db.dropRole(“‘restoreEx”);
修改密码:
db.changeUserPassword("restore",“pwd")
权限与用户:
db.grantRolesToUser("restore", [{role:"restoreEx",db:"admin"}])
db.revokeRolesFromUser("admin",["restore"])
权限与角色:
db.getRole( "restore", { showPrivileges: true } )
db. grantPrivilegesToRole("restore", [{resource:{db:"config",collection:"system.sessions"},actions:["find","insert","remove","update"]}])
代码100分
4.其它:
代码100分show users:只显示具体某个DB的用户
db.system.users.find():显示的是整个集群里的所有用户
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
转载请注明出处: https://daima100.com/9203.html