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