Configure user rights under MongoDB

Source: Internet
Author: User
Tags auth


MongoDB default is set to no permission access limitNote: The research results are based on the Windows platform
after a successful deployment of MongoDB. Go to the console:Enter the command:MongodUse Admin, you will find that the DB includes a system.user table, hehe. Yes, the table is equivalent to the user table in MSSQL. For the Super admin, let's just try to add a super admin to it.I joined a Super administrator user, username for Admin,password also for the admin, that is, we joined the super-administrator, then we will test, see if we connect MongoDB again need not be prompted to enter the user name, password. Let's just quit.

Input command:mongod Use admin

Input command: Show collections. Looking at all the tables under the library, you will find that MongoDB does not prompt you to enter username, password. That's weird, what's going on here? Mentioned at the beginning of the article.



MongoDB defaults to no permission access limit, that is, then we will first set it asAccess Restrictions Required, let's look at the effect, how to set it?

In the registration form, locate the node for MongoDB. In its imgpath, let's change it, add -auth, for example, see below:mongod

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

Note:Enter system Registration Form(Win+r-->regedit),Find[Hkey_local_machine-->system-->currentcontrolset-->services-->mongodb]on the right of the kin-in the value list, hit theImagePath"



after the changes have been made to the console again, found to need password verification.

The inputs username and password can be verified.
Don't worry, it's not finished yet.


When you exit the form. Once you have started the form again, after using the use MyDatabase to switch to a library, look at the table below the library and discover that there are no permissions. But. The previous command to enter the Admin library, and then verify username and password before entering the MyDatabase library is no problem.

So we can get into the MyDatabase library.

In the Join user db.adduser (Username,password);
This allows access to the MyDatabase Library through username and password.


In the same Linux environment, you will need to add the Auth to the start service to initiate access control.









Configure user rights under MongoDB

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.