An ApsaraDB for MongoDB replica set instance consists of three nodes by default. ApsaraDB for MongoDB provides connection strings for you to connect to the primary node and a secondary node. The other secondary node is hidden as a backup to ensure high availability. If a node is faulty, the high availability system of ApsaraDB for MongoDB automatically triggers a primary/secondary failover to ensue the availability of the instance. You also can manually trigger a primary/secondary failover for an ApsaraDB for MongoDB instance in scenarios such as routine disaster recovery drills.

Background information

After you call the SwitchDBInstanceHA operation or trigger a primary/secondary failover in the ApsaraDB for MongoDB console, ApsaraDB for MongoDB switches the roles of the primary and secondary nodes in a replica set instance.

  • You can trigger a primary/secondary failover only for replica set and sharded cluster instances, but not for standalone instances due to their single-node architecture.
  • After you trigger a primary/secondary failover for an instance, a transient connection error of up to 30 seconds will occur to the instance. Ensure that your applications can automatically re-establish a connection.
  • You can trigger a primary/secondary failover only for instances in the running state.


  1. Log on to the ApsaraDB for MongoDB console.
  2. In the left-side navigation pane, click Replica Set Instances.
  3. In the upper-left corner of the page, select the resource group and region to which the instance belongs.
  4. Click the ID of an instance, or click More icon in the Actions column corresponding to the instance and select Manage.
  5. In the Node List section, click Failover.
  6. In the Failover panel, set Effective At.
    • Effective Immediately: The system immediately performs a primary/secondary failover.
    • Maintenance Window:The system performs a primary/secondary failover within the specified maintenance window. You can select the current maintenance window or customize a maintenance window in the Change Maintenance Window drop-down list.
  7. Click the Submit tab.
    The instance status changes to Switching Role. The failover is successful when the instance status changes back to Running.
    • The failover takes about one minute. Then the instance returns to normal.
    • If you have connected to the connection string of the primary node for an instance, you are connecting to a secondary node after a failover and you have no write permissions on the instance. In this case, you must connect to the connection string of the new primary node and obtain read and write permissions. For more information, see Overview of replica set instance connections.