MongoDB – Local MultiDB & ReplicaSet Configurations for Development

Create directories like below:

 

 

Bat scripts for running each ReplicaSet instance:

 

start_db1_r1.bat:

E:\kim\mongodb-win32-i386-2.0.5\bin\mongod --dbpath "E:\kim\mongodb-win32-i386-2.0.5\data\db1\r1" --port 27118 --replSet bar1 -- rest

 

start_db1_r2.bat:

E:\kim\mongodb-win32-i386-2.0.5\bin\mongod --dbpath "E:\kim\mongodb-win32-i386-2.0.5\data\db1\r2" --port 27119 --replSet bar1 --rest

 

start_db1_r3.bat:

E:\kim\mongodb-win32-i386-2.0.5\bin\mongod --dbpath "E:\kim\mongodb-win32-i386-2.0.5\data\db1\r3" --port 27120 --replSet bar1 --rest

 

start_db2_r1.bat:

E:\kim\mongodb-win32-i386-2.0.5\bin\mongod --dbpath "E:\kim\mongodb-win32-i386-2.0.5\data\db2\r1" --port 27218 --replSet bar2 --rest

 

start_db2_r2.bat:

E:\kim\mongodb-win32-i386-2.0.5\bin\mongod --dbpath "E:\kim\mongodb-win32-i386-2.0.5\data\db2\r2" --port 27219 --replSet bar2 --rest

 

start_db2_r3.bat:

E:\kim\mongodb-win32-i386-2.0.5\bin\mongod --dbpath "E:\kim\mongodb-win32-i386-2.0.5\data\db2\r3" --port 27120 --replSet bar2 --rest

 

start_db3_r1.bat:

E:\kim\mongodb-win32-i386-2.0.5\bin\mongod --dbpath "E:\kim\mongodb-win32-i386-2.0.5\data\db3\r1" --port 27318 --replSet bar3 --rest

 

start_db3_r2.bat:

E:\kim\mongodb-win32-i386-2.0.5\bin\mongod --dbpath "E:\kim\mongodb-win32-i386-2.0.5\data\db3\r2" --port 27319 --replSet bar3 --rest

 

start_db3_r3.bat:

E:\kim\mongodb-win32-i386-2.0.5\bin\mongod --dbpath "E:\kim\mongodb-win32-i386-2.0.5\data\db3\r3" --port 27320 --replSet bar3 --rest

 


 

Backend script start.bat for running all-at-once:

 

start /b E:\kim\mongodb-win32-i386-2.0.5\data\db1\start_db1_r1.bat
start /b E:\kim\mongodb-win32-i386-2.0.5\data\db1\start_db1_r2.bat
start /b E:\kim\mongodb-win32-i386-2.0.5\data\db1\start_db1_r3.bat

start /b E:\kim\mongodb-win32-i386-2.0.5\data\db2\start_db2_r1.bat
start /b E:\kim\mongodb-win32-i386-2.0.5\data\db2\start_db2_r2.bat
start /b E:\kim\mongodb-win32-i386-2.0.5\data\db2\start_db2_r3.bat

start /b E:\kim\mongodb-win32-i386-2.0.5\data\db3\start_db3_r1.bat
start /b E:\kim\mongodb-win32-i386-2.0.5\data\db3\start_db3_r1.bat
start /b E:\kim\mongodb-win32-i386-2.0.5\data\db3\start_db3_r1.bat

 


 

Initial configurations:

 

E:\kim\mongodb-win32-i386-2.0.5\bin>mongo localhost:27118
> config = {_id:'bar1', members:[{_id:0, host:'localhost:27118'}, {_id:1, host:'localhost:27119'}, {_id:2, host:'localhost:27120'}]}
> rs.initiate(config);
> rs.status();
> use test
> db.addUser("kim", "kim")

 

E:\kim\mongodb-win32-i386-2.0.5\bin>mongo localhost:27218
> config = {_id:'bar2', members:[{_id:0, host:'localhost:27218'}, {_id:1, host:'localhost:27219'}, {_id:2, host:'localhost:27220'}]}
> rs.initiate(config);
> rs.status();
> use test
> db.addUser("kim", "kim")

 

E:\kim\mongodb-win32-i386-2.0.5\bin>mongo localhost:27318
> config = {_id:'bar3', members:[{_id:0, host:'localhost:27318'}, {_id:1, host:'localhost:27319'}, {_id:2, host:'localhost:27320'}]}
> rs.initiate(config);
> rs.status();
> use test
> db.addUser("kim", "kim")

 

Posted in MongoDB | Comments Off on MongoDB – Local MultiDB & ReplicaSet Configurations for Development