All Products
Search
Document Center

ApsaraDB for MongoDB:Configure a primary/secondary switchover for a replica set instance

Last Updated:Mar 28, 2026

ApsaraDB for MongoDB replica set instances run on a three-node architecture: a primary node, a secondary node, and a hidden node. The primary and secondary nodes provide external endpoints; the hidden node acts as a standby to support high availability. When a node fails, the high-availability system automatically triggers a primary/secondary switchover. Trigger a switchover manually for scenarios such as disaster recovery drills.

Prerequisites

Before you begin, ensure that you have:

  • A replica set or sharded cluster instance (standalone instances do not support primary/secondary switchovers due to their single-node architecture)

  • An instance in the Running state

  • An application that supports automatic reconnection (the instance will be disconnected for up to 30 seconds during the switchover)

Trigger a primary/secondary switchover

  1. Go to the Replica Set Instances page. In the top navigation bar, select a resource group and a region, then click the ID of the target instance.

  2. In the left navigation pane, click Service Availability.

  3. Click Switch Role.

  4. In the Switch Role panel, select the roles to switch under Roles, then set Effective At:

    OptionDescription
    Effective ImmediatelyThe switchover starts right away.
    Effective Within Maintenance WindowThe switchover runs within the configured maintenance window. To use a different window, select one from the Change Maintenance Window drop-down list.
  5. Click OK.

The instance status changes to Failing Over. When it returns to Running, the switchover is complete. The whole process takes about one minute.

Important

If your application connects directly to the primary node endpoint, update the connection string to use the new primary node endpoint. Otherwise, read and write operations may fail. For more information, see Connect to a replica set instance.

What's next

API reference

APIDescription
SwitchDBInstanceHASwitches the primary and secondary nodes for an ApsaraDB for MongoDB instance.