MongoDB (iv) MONGODB set user access rights

Source: Internet
Author: User

We know that MySQL will need us to set a database default username and password when installing,MongoDB is no exception, but MongoDB is the default does not set access restrictions, You do not need to enter a user name and password to access, but this is very insecure, we need to manually add the permission restrictions for MongoDB 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 SA and 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 ] in the right-hand list, hit "ImagePath" and add the -authas shown:


Note: After modifying the registry, be sure to manually restart the MongoDB service before it takes effect.

So when we open the mongodb Shell window again , look at the default database and "table", will be prompted to open the corresponding collections, and will error, as shown in.


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


after entering, we can build our own users again. Just like the user management in MySQL, We can add and remove users from the user table in MySQL, which is the same 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.

MongoDB (iv) 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.