I have setup 2 system with mongodb replication in ubuntu 16.4 , one is primary and another secondary, its working correctly but when the primary goes to down the secondary not comes as a primary, I have seted voting and priority using below commands , but still getting same. members ID I used "1" because secondary server running with ID 1 , which one I got from rs.status() and rs.status(). I have done replication using this url only.
> use admin
> rs.status()
> cfg = rs.conf()
> cfg.members = [cfg.members[1]]
> cfg.members[1].votes = 1;
> rs.reconfig(cfg, {force : true})
For automatic election to happen majority of instances need to be available. If we have a replica set of 3, majority is 2. Atleast 2 members needs to be available for election to happen.
In case of 2 member replica set, majority is 2 (1 is not majority). So the election will not happen when 1 node is down. The only ways is to force reconfigure.