Thursday, December 11, 2014

Azure Windows VM for MongoDB configuration and replica set



http://igorbicanic.blogspot.com/2014/11/install-and-configure-mongodb-replica.html?m=1

Create VM for Windows server
configure end point so port can open
configure Windows firewall to allow traffic for inbound and outbound








mongo --port 3000 //means connect to the specific port 3000

in mongodb shell

var democonfig= {_id: "MSWrs", members: [{_id:0,host: 'mswreg1.cloudapp.net:27017',priority:10}, {_id:1,host:'mswreg2.cloudapp.net:27017'}, {_id:2,host:'mswreg3.cloudapp.net:27017',arbiterOnly:true}]};

id demo
array of members
primary, 2nd, arbiteronly
priority 10 to make it default primary



initiate

rs.initiate(democonfig)



successfully initiated


on primary shell do:
db.foo.save({_id:1, value:'hellow world'})
db.foo.find()

then in 2nd shell do 
db.foo.find()

you will get error, then need to do the following to make it slave ok

db.setSlaveOK() // this is no longer work for v 2.6, use the one below:
db.getMongo().setSlaveOk()

then shutdown primary, then 2nd will change to primary


rs.status()



No comments:

Post a Comment