Stepping down as primary from the replica set

There are times when for some maintenance activity during business hours we would like to take a server out from the replica set, perform the maintenance and put it back in the replica set. If the server to be worked upon is the primary, we somehow need to step down from the primary member position, perform re-election and ensure that it doesn't get re-elected for a minimum given time frame. After the server becomes secondary once the step down operation is successful, we can take it out of the replica set, perform the maintenance activity and put it back in the replica set.

Getting ready

Refer to the recipe Starting multiple instances as part of a replica set from Chapter 1, Installing and Starting ...

Get MongoDB Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.