• Articles
  • Tutorials
  • Interview Questions

Replication

What is Replication in MongoDB?

Replication is the procedure of synchronizing the data across different servers. This feature increases data availability and provides redundancy. It secures the database from significant failure due to server downtime.

Not only this, Replication helps recover the database from a system failure by keeping additional copies of data.

MongoDB uses replica set which is a group of mongod instances that host the similar data sets. A replica consists of a primary node that receives all the write operations and all other instances apply operations from the primary node. Typically there is only one primary node and rest all are secondary nodes. Following diagram will help you understand the replication process in a better way :

replication

The client applications interact with the primary node which then replicates the data on the secondary nodes. The primary node is election with common consensus.

Big data

Procedure to create a replica set

In order to convert a standalone MongoDB instance into a replica set, follow given procedure –

  • If your MongoDB server is running, shut it down.
  • Restart the MongoDB server and select the ‘replset’ option and follow the instructions.

Following command will create a replica set-

mongod --port "PORT" --dbpath "YOUR_DB_DATA_PATH" --replSet "REPLICA_SET_INSTANCE_NAME"

Course Schedule

Name Date Details
MongoDB Training 23 Nov 2024(Sat-Sun) Weekend Batch View Details
30 Nov 2024(Sat-Sun) Weekend Batch
07 Dec 2024(Sat-Sun) Weekend Batch

About the Author

Data Engineer

As a skilled Data Engineer, Sahil excels in SQL, NoSQL databases, Business Intelligence, and database management. He has contributed immensely to projects at companies like Bajaj and Tata. With a strong expertise in data engineering, he has architected numerous solutions for data pipelines, analytics, and software integration, driving insights and innovation.