Replication is process of keeping multiple copies of the data on different database servers for high availability, disaster recovery, backups, and so on.
MongoDB supports asynchronous replication using one primary (master) server and multiple secondary (slave) servers. The replication can take place over LAN or WAN connections.
Replication is implemented in MongoDB using replica sets. A replica set is a group of MongoDB servers (mongod instances) that can be spread across different datacentres and geographic locations, with each server holding copies of the same data.
A replica set contains only one primary at any point in time and it receives all write operations from client applications. This ensures strict consistency for all read operations from the primary.
MongoDB uses statement based replication and to enable this, the primary logs all changes to its data in an operations log (oplog). The secondaries apply all operations in the primary's oplog to its own data set.
By default all Read operations are directed to the primary server which offers strict data consistency. However if an application does not require the most up to date data then it can perform Read operation on a secondary server by specifying a Read Preference and thereby improving the read throughput.
Replica sets in MongoDB supports automatic failovers. If the primary server fails then a new primary is elected by from the available secondary servers.