Replication in MongoDB is the process of matching data across multiple servers. Replication will offer and it will increase the data availability with multiple copies of data on different database servers. Replication will protect a database from the thrashing of a single server. Replication will also help in recovering from hardware failure and service interruptions. With additional copies of data, each data can be dedicated to disaster recovery, reporting, or backup.
MongoDB can achieve replication by using replica set. Replica set is a group of mongodb instances which hosts same data set. Replica has a primary node which receives all write operations. All other instances, such as secondaries, will apply operations from the primary so that they will have the same data set. Replica set can have only one primary node.
Typical diagram of MongoDB replication is shown below in which the client application always interact with the primary node and the primary node will then replicates the data to the secondary nodes.
In this tutorial, standalone MongoDB instance can be converted to a replica set. To convert to replica set, follow below steps
For adding members to replica set, start mongod instances on multiple machines. Now start a mongo client and issue a command rs.add().
Basic syntax of rs.add() command is as follows
Assume that your mongod instance name is mongod1.net and it is running on port 27017. To add this instance to replica set, issue the command rs.add() in Mongo client.
Mongod instance can be added to a replica set only when you are connected to primary node. To check if you are connected to primary or not, issue the command db.isMaster() in mongo client.
MongoDB Related Interview Questions
|Python Interview Questions||C & Data Structures Interview Questions|
|Hadoop Interview Questions||Node.js Interview Questions|
|Scala Interview Questions||Socket Programming Interview Questions|
|HBase Interview Questions||Solaris Administrator Interview Questions|
All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.