Thursday, 25 August 2016

How to create Replica Set in MongoDB

I am using mongoDB version 3.2.
I am assuming you have installed mongoDB on your machine.

Steps:
1. Open command prompt and navigate to "/bin" folder of mongoDB where mongod.exe files are stored.
mongod --replSet  abc  (Here abc is replica Set name) 
 Now you have created replica Set.

2. Now open mongo shell (node) in another window.
Again go  to "/bin" and run mongo.exe  

 3. Now you have already connected to test db.
   Initiate the replica set.
     rs.initiate();

 Now you can see replica set initialized on your shell.
Eg.<abc:PRIMARY>

or <abc:SECONDARY>
 etc.

No comments:

Post a Comment