Site icon Database Tutorials

Replica Set In Mongodb

Today I will tell you how to do Replica Set In Mongodb.

In this example, there are 3 servers, mongodb-node1, mongodb-node2 and mongodb-node3.

1. We must have set up MongoDB Community on all three nodes.

2. Edit the /etc/hosts file on all three nodes.

3. We edit the following parameters in the /etc/mongod.conf file and configure the MongoDB replication cluster.

4. We restart the MongoDB service on all three nodes for the changes to take effect.

5. In Primary, we start the MongoDB replication cluster.

6. We are adding other nodes.

TESTING

To test, we create a collection in the Primary and this collection is queried in the Secondary node.

As can be seen above, when we query the secondary node, the collection created in the primary is displayed. We have successfully created the replication cluster.

Exit mobile version