Yandex Cloud
Search
Contact UsGet started
  • Blog
  • Pricing
  • Documentation
  • All Services
  • System Status
    • Featured
    • Infrastructure & Network
    • Data Platform
    • Containers
    • Developer tools
    • Serverless
    • Security
    • Monitoring & Resources
    • ML & AI
    • Business tools
  • All Solutions
    • By industry
    • By use case
    • Economics and Pricing
    • Security
    • Technical Support
    • Customer Stories
    • Gateway to Russia
    • Cloud for Startups
    • Education and Science
  • Blog
  • Pricing
  • Documentation
Yandex project
© 2025 Yandex.Cloud LLC
Yandex Managed Service for MongoDB
  • Getting started
    • All guides
      • Managing shards
      • Selecting a different primary replica
  • Access management
  • Terraform reference
  • Monitoring metrics
  • Audit Trails events
  • Public materials
  • Release notes
  1. Step-by-step guides
  2. Sharding and replication
  3. Selecting a different primary replica

Selecting a different primary replica

Written by
Yandex Cloud
Updated at May 5, 2025

If a cluster has several replicas, you can select a different primary replica (master) as required.

Switching takes on average less than a minute. The cluster may be unavailable for writing for several seconds while switching is taking place.

For more information about selecting a different primary replica, see the MongoDB documentation.

Management console
CLI
REST API
gRPC API
  1. Go to the folder page and select Managed Service for MongoDB.
  2. Click the cluster name and open the Hosts tab.
  3. Click in the PRIMARY host row and select Step down.

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

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

To change a cluster's primary replica, run the command:

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

You can request the name of the shard primary replica with the list of cluster hosts and the cluster name, with the list of clusters in the folder.

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

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

    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_primary_replica_name>"
                 ]
                }'
    

    You can get the cluster ID with the list of clusters in the folder, and the name of the shard primary replica, with the list of cluster hosts.

  3. View the server response to make sure the request was successful.

  1. Get an IAM token for API authentication and put it into the 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 the repository contents are stored in the ~/cloudapi/ directory.

  3. Use the ClusterService.StepdownHosts call and send the following request, e.g., via gRPCurl:

    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_primary_replica_name>"
             ]
            }' \
        mdb.api.cloud.yandex.net:443 \
        yandex.cloud.mdb.mongodb.v1.ClusterService.StepdownHosts
    

    You can get the cluster ID with the list of clusters in the folder, and the name of the shard primary replica, with the list of cluster hosts.

  4. View the server response to make sure the request was successful.

Was the article helpful?

Previous
Managing shards
Next
Viewing cluster logs
Yandex project
© 2025 Yandex.Cloud LLC