Yandex Cloud
Documentation
PresentationContact UsTry it for free
© 2026 Direct Cursus Technology L.L.C.
Yandex StoreDoc
  • Getting started
    • All guides
      • Managing shards
      • Master failover
  • Access management
  • Inspections and recommendations
  • Pricing policy
  • Terraform reference
  • Monitoring metrics
  • Audit Trails events
  • Public materials
  • Release notes
  1. Step-by-step guides
  2. Sharding and replication
  3. Master failover

Master failover

Written by
Yandex Cloud
Updated at November 16, 2026
View in Markdown

In a cluster with multiple replicas, you can switch the master if required.

The switchover typically takes less than a minute. During the switchover, the cluster may be unwriteable for a few seconds.

Management console
CLI
REST API
gRPC API
  1. In the management console, select the folder.
  2. Navigate to Yandex StoreDoc.
  3. Click the name of your cluster and select the Hosts tab.
  4. Locate the PRIMARY host in the list, click in its row, and select Step down.

If you do not have the Yandex Cloud CLI yet, install and initialize it.

The folder used by default is the one specified when creating the CLI profile. To change the default folder, use the yc config set folder-id <folder_ID> command. You can also specify a different folder for any command using --folder-name or --folder-id.

If you access a resource by its name, the search will be limited to the default folder. If you access a resource by its ID, the search will be global, i.e., through all folders based on access permissions.

To switch the master in your cluster, run this command:

yc managed-mongodb hosts stepdown <current_master_name> \
   --name=<cluster_name>

You can get the master name for the required shard from the cluster's host list, and the cluster name, from the list of clusters in your folder.

  1. Get an IAM token for API authentication and put it into an environment variable:

    export IAM_TOKEN="<IAM_token>"
    
  2. Call the Cluster.StepdownHosts method, e.g., via the following cURL request:

    curl \
        --request POST \
        --header "Authorization: Bearer $IAM_TOKEN" \
        --header "Content-Type: application/json" \
        --url 'https://mdb.api.cloud.yandex.net/managed-mongodb/v1/clusters/<cluster_ID>:stepdownHosts' \
        --data '{
                 "hostNames": [
                    "<current_master_name>"
                 ]
                }'
    

    You can get the cluster ID from the list of clusters in your folder, and the master name for the required shard, from the cluster's host list.

  3. Check the server response to make sure your request was successful.

  1. Get an IAM token for API authentication and put it into an environment variable:

    export IAM_TOKEN="<IAM_token>"
    
  2. Clone the cloudapi repository:

    cd ~/ && git clone --depth=1 https://github.com/yandex-cloud/cloudapi
    

    Below, we assume that the repository contents reside in the ~/cloudapi/ directory.

  3. Call the ClusterService.StepdownHosts method, e.g., via the following gRPCurl request:

    grpcurl \
        -format json \
        -import-path ~/cloudapi/ \
        -import-path ~/cloudapi/third_party/googleapis/ \
        -proto ~/cloudapi/yandex/cloud/mdb/mongodb/v1/cluster_service.proto \
        -rpc-header "Authorization: Bearer $IAM_TOKEN" \
        -d '{
             "cluster_id": "<cluster_ID>",
             "host_names": [
                "<current_master_name>"
             ]
            }' \
        mdb.api.cloud.yandex.net:443 \
        yandex.cloud.mdb.mongodb.v1.ClusterService.StepdownHosts
    

    You can get the cluster ID from the list of clusters in your folder, and the master name for the required shard, from the cluster's host list.

  4. Check the server response to make sure your request was successful.

Was the article helpful?

Previous
Managing shards
Next
Viewing cluster logs
© 2026 Direct Cursus Technology L.L.C.