Reputation: 450
I have mongodb database with replication(1 primary and 4 secondary machine named as node1, node2,node3, node4 and node5 ). I want to assign priority to nodes. If node1
goes down then node2
should become primary If node1
and node2
goes down then node3
should become primary and so on.
I am trying to assign priority Using below command but it is not changing:
cfg = rs.conf()
cfg.members[0].priority = 20
cfg.members[1].priority = 15
cfg.members[2].priority = 10
cfg.members[3].priority = 5
cfg.members[4].priority = 1
rs.reconfig(cfg)
I am using Mongodb version: 3.2
Upvotes: 1
Views: 2560
Reputation: 15792
You have to configure votes also.
cfg = rs.conf()
cfg.members[0].votes = 1;
cfg.members[0].priority = 20;
cfg.members[1].votes = 1;
cfg.members[1].priority = 15;
cfg.members[2].votes = 1;
cfg.members[2].priority = 10;
cfg.members[3].votes = 1
cfg.members[3].priority = 5;
cfg.members[4].votes = 1
cfg.members[4].priority = 1;
rs.reconfig(cfg);
IMPORTANT Changed in version 3.2:
Non-voting members must have
priority of 0. Members with priority greater than 0 cannot have 0 votes.
To configure a member as non-voting, set both its votes and priority values to 0.
Refer MongoDB Documentation for more info about votes and priority.
Upvotes: 4