Forces the primary of the replica set to become a secondary, triggering an election for primary. The method steps down the primary for a specified number of seconds; during this period, the stepdown member is ineligible from becoming primary.
The method only steps down the primary if an electable secondary is up-to-date with the primary, waiting up to 10 seconds for a secondary to catch up.
The method is only valid against the primary and will error if run on a non-primary member.
The rs.stepDown() method has the following parameter:
Parameter Type Description seconds number Optional. The number of seconds to step down the primary, during which time the stepdown member is ineligible from becoming primary. If this parameter is unspecified, the method uses the default value of 60 seconds.
rs.stepDown() provides a wrapper around the command replSetStepDown.
New in version 3.0.
Before stepping down, rs.stepDown() will attempt to terminate long running user operations that would block the primary from stepping down, such as an index build, a write operation or a map-reduce job.
To avoid rollbacks, rs.stepDown() only steps down the primary if an electable secondary is completely caught up with the primary. The method will wait up to the 10 seconds for a secondary to catch up.
If no electable secondary meets this criterion by the waiting period, the primary does not step down and the method throws an exception.
If the rs.stepDown() completes successfully, the method forces all clients currently connected to the database to disconnect. This helps ensure that the clients maintain an accurate view of the replica set. The mongo shell will display an error related to the disconnect.
rs.stepDown() blocks all writes to the primary while it runs.