Login verification and user management of MongoDB Foundation

Source: Internet
Author: User

First, super Administrator create and turn on login verification

If MongoDB is to turn on login verification, you must create a super administrator before you turn on login verification, or you will not be able to log in to the database!

For example, create a Super admin admin, Associate to the admin database, and set the role to root (super Admin)

First, go to the target library Admin,use admin

Then, enter the instruction db.createuser ({User: "admin", pwd: "123456", roles:["root"})

After you have created the administrator user, you can turn on login verification, enter the configuration file c:\MongoDB\config\mongodb.conf,

Add auth=true can turn on login verification, if you want to turn on Telnet, you need to add bind_ip=0.0.0.0, modify the Write restart MongoDB service.

Once the service is turned on, you can log in through the administrator,

Second, add the database of ordinary users

If you want to add the logged-on user to the specified database, first switch to the database, then create the user, the user needs to bind the database, and the role

Commonly used role Description:

READ: Allows the user to read the specified database
ReadWrite: Allows the user to read and write to the specified database
DbAdmin: Allows the user to perform administrative functions in the specified database, such as index creation, deletion, viewing statistics, or accessing System.profile
Useradmin: Allows the user to write to the System.users collection to create, delete, and manage users in the specified database
Clusteradmin: Available only in the admin database, giving the user administrative privileges on all shards and replica set related functions.
Readanydatabase: Only available in the Admin database, giving users read access to all databases
Readwriteanydatabase: Only available in the Admin database, giving users read and write access to all databases
Useradminanydatabase: Only available in the Admin database, giving the user useradmin permissions for all databases
Dbadminanydatabase: Only available in the Admin database, giving the user dbadmin permissions for all databases.
Root: Available only in the admin database. Super account, Super privilege

For example, create a test user with read and write permissions to the test database

First, go to the target library Test,use test

Then, enter the instruction db.createuser ({User: "Test", pwd: "123456", Roles:[{role: "ReadWrite", DB: "Test"}]})

Third, view all users

Switch to the admin database with Super Admin login, db.system.users.find () to view all the information of all users,
View all user profiles via directive Db.system.users.find ({},{user:1,roles:1,_id:0})

Iv. Modification of users

4.1 Modifying user passwords

For example, modify the password for user test to 123

First, go to the target library Test,use test

Then, enter the instruction Db.changeuserpassword ("Test", "123")

4.2 Modifying user Roles

To add a user role

For example, add ReadWrite permissions to the user test

First, go to the target library Test,use test

Then, enter the instruction db.grantrolestouser ("test", [{role: "ReadWrite", DB: "Test"}])

Remove a user Role

For example, remove the ReadWrite permission for the user test

First, go to the target library Test,use test

Then, enter the instruction db.revokerolesfromuser ("test", [{role: "ReadWrite", DB: "Test"}])

V. Delete users

For example, delete the user test

First, go to the target library Test,use test

Then, enter the instruction db.dropuser ("test")

Login verification and user management of MongoDB Foundation

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.