Create a Super User
Use Admindb.createuser ( { "Adminusername", "UserPassword", roles: [ { "useradminanydatabase", "admin" } ] })
There are two types of superuser role, useradmin or useradminanydatabase (more access to all databases than the previous one).
DB is the name of the specified database, and admin is the management database.
Log in with the newly created user
MONGO--host xxx-u adminusername-p userpassword--authenticationdatabase Admin
View permissions for the current user
Db.runcommand ( { usersinfo:"UserName", showprivileges:true })
Create a general user, also with CreateUser
Use Db01db.createuser ( { User:"oneuser", pwd:"12345", roles:[ { Role:"read", DB: "Db01"}, {role:"read", DB: "DB02"}, {role:"read", DB: "DB03" } ] })
Create a superuser who is not restricted by access
Use Admindb.createuser ( { User:"superuser", pwd:"pwd", roles:["root" ] })
Change Password
Use Admindb.changeuserpassword ("username", "xxx")
View user Information
Db.runcommand ({usersinfo: "UserName"})
Modify password and user information
Db.runcommand ( { updateUser:"username", pwd:"xxx", customdata:{ Title:"xxx"} })
Attention:
1. and user management related operations are basically to run under the Admin database, to use the admin first;
2. If under a single database, it can only operate on the permissions of the current database.
MongoDB User Management