Force a Member to Become Primary
Optionally, you also can force a member never to become primary by setting its
members[n].priority value to
0, which means the member can never seek election as primary. For more information, see Priority 0 Replica Set Members.
For more information on priorities, see
A majority of the configured members of a replica set must be available for a set to reconfigure a set or elect a primary. See Replica Set Elections for more information.
Changed in version 3.6.7: If the parameter
enableElectionHandoff is true (default), when a primary steps down from
rs.stepDown() (or the
replSetStepDown command without the
force: true), the stepped-down primary nominates an eligible secondary to call an election immediately. Otherwise, secondaries can wait up to
settings.electionTimeoutMillis before calling an election. The stepped down primary does not wait for the effects of the handoff. For more information, see
This procedure assumes your current primary is
m1.example.net and that you’d like to instead make
m3.example.net primary. The procedure also assumes you have a three-member replica set with the configuration below. For more information on configurations, see Replica Set Configuration Use.
This procedure assumes this configuration:
mongoshell connected to the primary, use the following sequence of operations to make
The following sequence of events occur:
m1.example.net(typically within 10 seconds).
m1.example.netsees that it no longer has highest priority and, in most cases, steps down.
m1.example.netdoes not step down if
m3.example.net’s sync is far behind. In that case,
m3.example.netis within 10 seconds of its optime and then steps down. This minimizes the amount of time with no primary following failover.
- The step down forces on election in which
m3.example.netbecomes primary based on its
m3.example.netis more than 10 seconds behind
m1.example.net’s optime, and if you don’t need to have a primary designated within 10 seconds, you can force
m1.example.netto step down by running:
m1.example.netfrom being primary for 86,400 seconds (24 hours), even if there is no other member that can become primary. When
m3.example.netcatches up with
m1.example.netit will become primary.
If you later want to make
m1.example.netprimary again while it waits for
m3.example.netto catch up, issue the following command to make
m1.example.netseek election again:
Consider a replica set with the following members:
mdb0.example.net- the current primary.
mdb1.example.net- a secondary.
mdb2.example.net- a secondary .
To force a member to become primary use the following procedure:
During the transition, there is a short window where the set does not have a primary.