MongoDB set user name and password

Source: Internet
Author: User

Requirements: We need to create a new two database on a mongodb, each database user name and password is not the same, the rationale is that we directly set the admin, you can control all the database, but used to always feel a variety of problems, is not very familiar with MongoDB, So directly to the different database set user name and password, can achieve the desired effect. You cannot see the database when you test with mongobooster without entering a user name and password.

The user name and password for MongoDB are mapped to each specific database.

Here are some commands to keep in check:

1, the first time we start MongoDB, if need to modify the normal way to start

Mongod-f/etc/mongod.conf

New Database Testlog

Use Logmanagerment

Create a table

Db.createcollection ("account")

This time if you restart MongoDB will be able to find that we have a database, and now we set the user name and password, the password is best not to have the @ symbol, placed in the URL may conflict username:[email protected]:27017

Db.createuser (
{
User: "username",
PWD: "Password",
Roles: [{role: ' ReadWrite ', db: ' Testlog '}]
}
)

Creating another database is the same, you need to kill the previous MongoDB process after it is created, ps-ef| grep Mongod, then kill it, then start with permission, Mongod--auth-f/etc/mongod.conf, and then we connect and discover that the permissions have been set successfully

2, if we need to modify the existing user name and password, the first need to switch off the existing MongoDB process, and then the normal way to start MongoDB

Use Yourdatabase

Db.changeuserpassword ("username", "password")//Enter after no response, in fact, has been modified to restart MongoDB, in order to need permission to start, you can see the effect of

  

MongoDB set user name and password

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.