Replication
A replica set in MongoDB refers to a collection of mongod
processes that uphold the same dataset. They offer redundancy and high availability, serving as the foundation for all production implementations. By having numerous data copies across various database servers, replication ensures a degree of fault tolerance, protecting against the failure of a single database server.
Figure 2.1: A replica set
The primary node handles all write operations, and logs all dataset changes in its operations log (oplog). A MongoDB replica set can only have one primary node.
The secondary nodes replicate the primary's oplog, and implement the operations on their own datasets, ensuring that they mirror the primary's dataset. In the event of the primary becoming inaccessible, a qualified secondary will initiate an election to become the new primary.
With data stored across multiple servers, replication increases the reliability of the system....