方法名 | 描述 |
---|---|
db.getUsers() | |
db.dropAllUsers() | |
db.updateUser() | |
db.createUser() | |
db.revokeRolesFromUser() | |
db.removeUser() | 删除用户 |
db.grantRolesToUser() | |
db.getUser() | |
db.changeUserPassword() | |
db.auth() | 数据库认证、安全模式 |
创建超级账号:要在admin数据库下面创建超级账号:
选择数据库:use admin
创建用户:db.createUser({user:"glc",pwd:"glc",roles:[{role:"root",db:"admin"}]})
检测密码:db.auth("username","password")
glc-test:PRIMARY> use admin switched to db admin glc-test:PRIMARY> db.createUser({user:"glc",pwd:"glc",roles:[{role:"root",db:"admin"}]}) Successfully added user: { "user" : "glc", "roles" : [ { "role" : "root", "db" : "admin" } ] } glc-test:PRIMARY> db.auth("glc","glc") 1
创建某个库有创建索引的权限:
replset_name:PRIMARY> use admin switched to db admin replset_name:PRIMARY> db.createRole({role:"role_name",privileges: [{ resource: { db: "db_name", collection: "" }, actions: [ "createIndex" ]}],roles:[]})