Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Convert secondary Node to primary if maximum of node down in a replica set?

Tags:

mongodb

I am using mongodb with replica set ,which have 3 nodes lets their ip's are 192.168.1.100 , 192.168.1.101,192.168.1.102 .

In MY current setup 192.168.1.100 is Primary and others are Secondary .I have set priority for 192.168.1.100 and 192.168.1.101 is 1 and for 192.168.1.102 is 0 , now After some time my 192.168.1.100 and 192.168.1.101 both node are down .

I want to force 192.168.1.102 to become primary so that My application will live . Is their is any way to Forcefully convert 192.168.1.102 node to become primary NODE.

like image 916
Rajnish Avatar asked May 02 '13 05:05

Rajnish


1 Answers

You can achieve it without mongod service restart by below steps-

connect to active member suppose it is running on localhost on 27017 port:

mongo --port 27017

Get your member ids from here-

> use admin
> rs.status()

Suppose your active member id is 1. then reconfigure your replication as per below steps-

> cfg = rs.conf()
> cfg.members = [cfg.members[1]]
> rs.reconfig(cfg, {force : true})

It will make your remiaining active member to primary and available for application and writes.

like image 104
Zafar Malik Avatar answered Nov 07 '22 20:11

Zafar Malik