The priority settings of replica set members affect both the timing and the outcome of elections for primary. Higher-priority members are more likely to call elections, and are more likely to win. Use this setting to ensure that some members are more likely to become primary and that others can never become primary.
The value of the member’s priority setting determines the member’s priority in elections. The higher the number, the higher the priority.
优先级越大,被选举成primary的机会就越大,修改的方式如下:
Copy the replica set configuration to a variable.
In the mongo shell, use rs.conf() to retrieve the replica set configuration and assign it to a variable. For example:
cfg = rs.conf()
Change each member’s priority value.¶
Change each member’s members[n].priority value, as configured in the members array.
cfg.members[0].priority = 0.5
cfg.members[1].priority = 2
cfg.members[2].priority = 2
Assign the replica set the new configuration.¶
Use rs.reconfig() to apply the new configuration.
rs.reconfig(cfg)