In layman's MongoDB (d) MongoDB set user access rights

Source: Internet
Author: User


We know MySQL we need to set a default user name and password for the database during installation. MongoDB It's no exception, but MongoDB The default is not set access restrictions, do not need to enter the user name and password can be accessed, but this is very insecure, we need to manually MongoDB Add a permission limit command.

first set up a default account

Use Admin

db.adduser (' sa ', ' sa ')

This allows us to set up a default account with the username saand the password sa .

At this point we can still not enter the user name and password into the database, next we make the following changes.

Open the registry where MongoDB resides:

Win+r run regeditand find [hkey_local_machine-->system-->currentcontrolset-- >SERVICES-->MONGODB] On the right of the Jian-value list, hit "ImagePath", add the -authas shown:


Note: After modifying the registry, be sure to restart it manually MongoDB service so that it will take effect.

So When we open the mongodb Shell window again, view the default database and "table", we will be prompted not to open the corresponding Collections, and will error, as shown in.


when we use the previously added user login will be displayed, 1 The default is the correct user name and password.


After entering, we can build our own users again. Just like the user management in MySQL , we can add and remove users in MySQL 's user table, The same is true in MongoDB. For example, we add an admin:

Db.adduser (' admin ', ' admin ')


Note: The above is operating in the Windows environment and is consistent in Linux.


In layman's MongoDB (d) MongoDB set user access rights

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.