1. Create a Superuser use admin
Db.createuser ({User: "Accountuser", pwd: "Password", roles: ["ReadWrite", "DbAdmin"]}) Db.createuser ({User: "Adminusername", pwd: "UserPassword", roles: [{roles: "Useradminanydatabase", DB: "ADM In "}]})
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.
2. Log in with the newly created user
MONGO--host xxx-u adminusername-p userpassword--authenticationdatabase Admin
3. View the permissions of the current user
Db.runcommand ({usersinfo: "UserName", showprivileges:true})
4. Create a general user, also with CreateUser use Db01 db.createuser ({User: "Oneuser", pwd: "12345", roles:[{role: "read", DB: "Db01"}, {role: "read", DB: "DB02"}, {role: "read", DB: "DB03"}]})
5. Create a superuser who is not restricted by access
Use admin db.createuser ({User: "Superuser", pwd: "pwd", roles:["root"})
6. Change Password Use admin db.changeuserpassword ("username", "xxx")
7. View user Information
Db.runcommand ({usersinfo: "UserName"})
8. Change Password and user information
Db.runcommand ({updateUser: "username", pwd: "xxx", Customdata:{title: "XXX"})
Note:
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;
3. Db.adduser is the old version of the operation, now the version can also continue to use, created by the user is a root role of the Super Administrator
MongoDB Create user