Data Replication Implementation
To start three MongoDB instances on Single Machine (node.)
Thank You :)
Anshul Shrivastava
- Start Three MongoDB instances -
- Go to Command Prompt -
- Go to the directory where mongodb is extracted or installed.
- Run following commands-
- >mongod --port 27001 --dbpath "C:\Data\rep1" --replSet replication
- >mongod --port 27002 --dbpath "C:\Data\rep2" --replSet replication
- >mongod --port 27003 --dbpath "C:\Data\rep3" --replSet replication
- replSet identifier/name should be the same for all the instances eg. "replication".
- Start one MongoDB instance
- >mongo.exe --port 27001
- Run this command -
- cfg = {_id:"replication",members:[{_id:1,host:"localhost:27001"}, {_id:2,host:"localhost:27002"},{_id:3,host:"localhost:27003"}] }
- rs.initiate(cfg).
- Then CHECK THE STATUS -
- rs.status()
- rs.slaveOk() - While retrieving data in SECONDARY node or instance. It should be recognize that it is slave.
Thank You :)
Anshul Shrivastava