You can call this operation to switch between the primary and secondary nodes in a MongoDB instance.

The instance must be in the running state when you call this operation.

  • This operation is applicable to replica set instances and sharded cluster instances. SwitchDBInstanceHA cannot be performed on standalone instances.
  • On replica set instances, the switch is performed between instances. On sharded cluster instances, the switch is performed between shards.


OpenAPI Explorer simplifies API usage. You can use OpenAPI Explorer to perform debugging operations, such as retrieve APIs, call APIs, and dynamically generate SDK example code.

Request parameters

Parameter Type Required Example Description
Action String Yes SwitchDBInstanceHA

The operation that you want to perform. Set the value to SwitchDBInstanceHA.

DBInstanceId String Yes dds-bpxxxxxxxx

The ID of the instance.

NodeId String No d-bpxxxxxxxx

The ID of the shard in the sharded cluster instance.

Note You must specify this parameter when the value specified for DBInstanceId is the ID of a sharded cluster instance. Otherwise, ignore this parameter.
RoleIds String No 972xxxx

The ID of the role to be switched. You can call DescribeRoleZoneInfo to get role ID and node role information.

  • Separate role IDs with commas (,). If this parameter is not specified, the primary node and the secondary node are created.
  • When the DBInstanceId parameter is specified to the ID of a sharded cluster instance, the switch must belong to the same Shard.
AccessKeyId String No LTAIgbTGpxxxxxx

The AccessKey ID that Alibaba Cloud provides for you to access services.

Response parameters

Parameter Type Example Description
RequestId String 26BD4E5F-BDB4-47BA-B232-413AA78CFA8F

The ID of the request.


Sample requests

http(s):// Action=SwitchDBInstanceHA
&<Common request parameters>

Successful response examples

XML format


JSON format


Error codes

For a list of error codes, visit the API Error Center.