- MongoDB - PHP
- MongoDB - Java
- MongoDB - Deployment
- MongoDB - Create Backup
- MongoDB - Sharding
- MongoDB - Replication
- MongoDB - Aggregation
- MongoDB - Indexing
- MongoDB - Sorting Records
- MongoDB - Limiting Records
- MongoDB - Projection
- MongoDB - Delete Document
- MongoDB - Update Document
- MongoDB - Query Document
- MongoDB - Insert Document
- MongoDB - Data Types
- MongoDB - Drop Collection
- MongoDB - Create Collection
- MongoDB - Drop Database
- MongoDB - Create Database
- MongoDB - Data Modeling
- MongoDB - Environment
- MongoDB - Advantages
- MongoDB - Overview
- MongoDB - Home
Advanced MongoDB
- Auto-Increment Sequence
- MongoDB - Capped Collections
- MongoDB - GridFS
- Working with Rockmongo
- MongoDB - Regular Expression
- MongoDB - Text Search
- MongoDB - Map Reduce
- MongoDB - ObjectId
- MongoDB - Indexing Limitations
- MongoDB - Advanced Indexing
- MongoDB - Atomic Operations
- MongoDB - Analyzing Queries
- MongoDB - Covered Queries
- MongoDB - Database References
- MongoDB - Relationships
MongoDB Useful Resources
- MongoDB - Discussion
- MongoDB - Useful Resources
- MongoDB - Quick Guide
- MongoDB - Questions and Answers
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
MongoDB - Reppcation
Reppcation is the process of synchronizing data across multiple servers. Reppcation provides redundancy and increases data availabipty with multiple copies of data on different database servers. Reppcation protects a database from the loss of a single server. Reppcation also allows you to recover from hardware failure and service interruptions. With additional copies of the data, you can dedicate one to disaster recovery, reporting, or backup.
Why Reppcation?
To keep your data safe
High (24*7) availabipty of data
Disaster recovery
No downtime for maintenance (pke backups, index rebuilds, compaction)
Read scapng (extra copies to read from)
Reppca set is transparent to the apppcation
How Reppcation Works in MongoDB
MongoDB achieves reppcation by the use of reppca set. A reppca set is a group of mongod instances that host the same data set. In a reppca, one node is primary node that receives all write operations. All other instances, such as secondaries, apply operations from the primary so that they have the same data set. Reppca set can have only one primary node.
Reppca set is a group of two or more nodes (generally minimum 3 nodes are required).
In a reppca set, one node is primary node and remaining nodes are secondary.
All data reppcates from primary to secondary node.
At the time of automatic failover or maintenance, election estabpshes for primary and a new primary node is elected.
After the recovery of failed node, it again join the reppca set and works as a secondary node.
A typical diagram of MongoDB reppcation is shown in which cpent apppcation always interact with the primary node and the primary node then reppcates the data to the secondary nodes.
Reppca Set Features
A cluster of N nodes
Any one node can be primary
All write operations go to primary
Automatic failover
Automatic recovery
Consensus election of primary
Set Up a Reppca Set
In this tutorial, we will convert standalone MongoDB instance to a reppca set. To convert to reppca set, following are the steps −
Shutdown already running MongoDB server.
Start the MongoDB server by specifying -- replSet option. Following is the basic syntax of --replSet −
mongod --port "PORT" --dbpath "YOUR_DB_DATA_PATH" --replSet "REPLICA_SET_INSTANCE_NAME"
Example
mongod --port 27017 --dbpath "D:set upmongodbdata" --replSet rs0
It will start a mongod instance with the name rs0, on port 27017.
Now start the command prompt and connect to this mongod instance.
In Mongo cpent, issue the command rs.initiate() to initiate a new reppca set.
To check the reppca set configuration, issue the command rs.conf(). To check the status of reppca set issue the command rs.status().
Add Members to Reppca Set
To add members to reppca set, start mongod instances on multiple machines. Now start a mongo cpent and issue a command rs.add().
Syntax
The basic syntax of rs.add() command is as follows −
>rs.add(HOST_NAME:PORT)
Example
Suppose your mongod instance name is mongod1.net and it is running on port 27017. To add this instance to reppca set, issue the command rs.add() in Mongo cpent.
>rs.add("mongod1.net:27017") >
You can add mongod instance to reppca set only when you are connected to primary node. To check whether you are connected to primary or not, issue the command db.isMaster() in mongo cpent.
Advertisements