Mongodb Introduction:

Mongo is a open source database which uses nosql mechanism to store the data. The advantage of mongodb is simple and no structure is required.

Mongodb Installation:

  1. Create a file mongodb-org-3.2.repo with the following content on /etc/yum.repos.d/mongodb-org-3.2.repo


name=MongoDB Repository





2. Install MongoDB server.

    yum install -y mongodb-org

3. Modify the DB path if you want(/etc/mongodb.conf)

    dbPath: /opt/mongodata

4. Start the mongo Service

    sudo service mongod start

5. Add the service on reboot safe.

    chkconfig mongod on



If the mongo is accessed locally, we can leave the bind IP address. If mongodb is called by remote server then we need to bind the port to interface or all interface.

1. Comment out bindIp: on /etc/mongodb.conf


More information:

Settingup Mongo Cluster:

1. Make sure that there is a connection between hosts to the port 27017.

2. Modify /etc/mongodb.conf with replication configuration on all the hosts.


          replSetName: <replicationname>

3. Restart Mongod service on all Hosts.

4. On primary hosts, login to mongo terminal and execute the following command.

    >conf = {

          _id: “<replicationName>”,



                       {_id : 0, host : “Host1IPAddress:27017”},

                       {_id : 1, host : “Host2IPAddress:27017”},

                       {_id : 2, host : “Host3IPAddress:27017”}




5. Check the replication status.



More Information:


Additional Information:

Mongo has a feature arbiter.An arbiter does not have a copy of data set and cannot become a primary.Replica sets may have arbiters to add a vote in elections of for primary.


To add a host which will act as arbiter, follow below information.

1. Remove the host from existing cluster incase if the host already added in the cluster.


2. On Primary replication cluster,


3. Check the replication configuration. You might have seen “arbiterOnly” : true,



Bonus Information:

To get current running queries on Mongodb


To make the primary to secondary, execute below mentioned command


To check Replication Status.


To check whether the host is master or not.


Leave a Reply