Configure user permissions in MongoDB

Source: Internet
Author: User

Configure user permissions in MongoDB

By default, apsaradb for MongoDB is set to have no access restrictions. Note: The research results are based on the Windows platform.
After successfully deploying mongodb, go to the console and enter the command mongod use admin. You will find that the database contains a system. user table, huh, huh, right. This table is equivalent to the user table in MsSql, which is used to store super administrator data, let's add a super administrator to it and try to add a super administrator user. username is admin and password is admin. Then, we have added a super administrator, let's test the connection. If you need to connect to MongoDB again, you do not need to enter the username and password. Let's quit first.

Enter the command: mongod use admin

Run the show collections command to view all the tables in the database. You will find that MongoDB does not prompt you to enter the user name and password. That's strange. What is the problem? As mentioned at the beginning of this article,



By default, apsaradb for MongoDB is set to have no access permission. In this case, we need to set it as a permission access restriction first. Let's look at the effect. How can we set it?

In the registry, find the MongoDB node. In its ImgPath, modify it and add-auth, as shown below: mongod

"D: \ Program Files \ mongodb \ bin \ mongod"-dbpath e: \ work \ data \ mongodb \ db-logpath e: \ work \ data \ mongodb \ log-auth-service

Note: Go to the system registry (WIN + R --> regedit ), find [HKEY_LOCAL_MACHINE --> SYSTEM --> CurrentControlSet --> Services --> MongoDB] and press "ImagePath" in the "Health-Value List" on the right"



After the modification is complete, go to the console again and find that password verification is required.

Enter the user name and password for verification.
Don't worry. It's not over yet.
After exiting the window, start again and enter the window. use mydatabase to switch to another database and view the tables under the database. However, if you run the preceding command to access the admin database, then verify the username and password before entering the mydatabase database. In this way, you can access the mydatabase and add the user db. addUser (username, password );
In this way, you can use the user name and password to access the mydatabase.


Similarly, in linux, you must add the auth parameter after the started service to enable access control.









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.