In some cases (for example, if we have multiple data centers), we will want some of the members to never be able to become a primary server.
In a scenario with multiple data center replications, we may have our primary data center with one primary and one secondary based in the UK, and a secondary server located in Russia. In this case, we don't want our Russia-based server to become primary, as it would incur latency on our application servers based in the UK. In this case, we will set up our Russia-based server with priority as 0.
Replica set members with priority as 0 also can't trigger elections. In all other aspects, they are identical to every other member in the replica set. To change the priority of a replica set member, we must first get the current replica set configuration by connecting (via the mongo shell) to the primary server:
> cfg = rs.conf()
This will provide the config document that contains the configuration for every member in our replica set. In the members sub-document, we can find the priority attribute, which we have to set to 0:
> cfg.members[2].priority = 0
Finally, we need to reconfigure the replica set with the updated configuration:
rs.reconfig(cfg)