Configure user rights under MongoDB

Source: Internet
Author: User


MongoDB defaults to No access restrictionsNote: The research results are based on the Windows platform
after you have successfully deployed MongoDB, go to the console:Enter the command:Mongoduse admin, you will find that the DB contains a system.user table, hehe, yes, this table is equivalent to the user table in MSSQL, used to store the Super administrator, then we add a super admin to it to tryI add a super Admin user, username for Admin,password also for the admin, that is, we added Super administrator, then we come to test, see if we connect MongoDB again need not prompt to enter the user name, password, we first exit

Input command:mongod Use admin

Input command: Show collections, look at all the tables under the library, you will find that MongoDB does not prompt you to enter the user name, password, it is strange, this is how it? Mentioned at the beginning of the article,



MongoDB defaults to No access restrictions, that is, then we will set it aspermission access restrictions are required, let's look at the effect, how to set it?

In the registry, find the node of MongoDB, in its imgpath, we modify, add -auth, as follows:Mongod

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

Note: Enter the system registration form (Win+r-->regedit), find [hkey_local_machine-->system-->currentcontrolset-->services--> MongoDB] on the right of the kin - List of values hit   " imagepath "



Once the modification is complete, the console is entered again and the password verification is required.

The user name and password can be entered to verify.
Don't worry, it's not finished yet.
When you exit the window, after you start the window again, after using the use MyDatabase to switch another library, look at the table below the library and discover that there are no permissions. However, the previous command to enter the Admin library, and then verify the user name and password before entering the MyDatabase library is no problem. This allows us to enter the MyDatabase library after adding user db.adduser (Username,password);
This allows you to enter the MyDatabase library with your username and password.


Also in the Linux environment, you need to add auth parameters to start the access control after starting the service.









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.