3. Analysis of MONGODB User management

Source: Internet
Author: User

Network Source--http://www.jb51.net/article/53830.htm

1. Create a Super User

Db.createuser (  {    User: "li0924",    pwd: "123",    roles:    [      {        role: "Useradminanydatabase",        db: "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.

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 use CreateUser

Use Db01db.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 Admindb.createuser (  {    User: "Superuser",    pwd: "pwd",    roles:["root"  })

6. Change the password

Use Admindb.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 an older version of the operation, now the version can also continue to use, created by the user is a root role of the Super administrator.

3. Analysis of MONGODB User management

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.