Reference Guide

Create DBadmin user for MongoDB
Login to the MongoDB using the user account created in the previous section. The DBadmin user is created with the administrative
privileges.
Run the following command to create the DBadmin user:
mongo -uDBUser -pPassword admin
use admin
db.createUser( {
user: "DBadmin",
pwd: <DBadmin user password>,
roles: [ { role: "DBadmin", db: "admin" } ]
})
Edit mongod.cfg le
You must edit the mongod.cfg le to enable the security for the MongoDB database.
1 Login to MongoDB as root user that you have already created and run the following command:
mongo -uroot -<root password> admin
2 Go to \data\bin\mongod.cfg directory, and open mongod.cfg le in a text editor.
3 Edit mongod.cfg le as shown in the following command:
Figure 56. Edit mongod.cfg
systemLog:
destination: file
path: c:\data\log\mongod.log
storage:
dbPath: c:\data\db\Mongo
net:
port: 27017
security:
authorization: enabled
NOTE
: The port numbers will change depending on the system at the work place.
4 Save mongod.cfg and exit.
Initiate replication on the servers
Ensure that you disable rewall on Windows and stop Tomcat servers if they are running.
1 Login to MongoDB as root user that you have already created and run the following command:
mongo -uroot -<root password> admin
Achieve high availability on MongoDB
61