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
    • Cloud credits to scale your IT product
    • Gateway to Russia
    • Cloud for Startups
    • Education and Science
    • Yandex Cloud Partner program
  • Blog
  • Pricing
  • Documentation
© 2025 Direct Cursus Technology L.L.C.
Yandex Managed Service for MongoDB
  • Getting started
    • All guides
      • Information about existing clusters
      • Creating a cluster
      • Updating cluster settings
      • MongoDB version upgrade
      • Stopping and starting a cluster
      • Managing cluster hosts
      • Migrating hosts to a different availability zone
      • Managing backups
      • Deleting a cluster
  • Access management
  • Terraform reference
  • Monitoring metrics
  • Audit Trails events
  • Public materials
  • Release notes

In this article:

  • Getting a list of cluster hosts
  • Adding a host
  • Changing a host
  • Removing a host
  • Starting host resync
  • Restarting a host
  1. Step-by-step guides
  2. Clusters
  3. Managing cluster hosts

Managing MongoDB cluster hosts

Written by
Yandex Cloud
Updated at May 5, 2025
  • Getting a list of cluster hosts
  • Adding a host
  • Changing a host
  • Removing a host
  • Starting host resync
  • Restarting a host

You can add and remove cluster hosts, resync the hosts, and manage MongoDB settings for individual clusters. To learn how to move your cluster hosts to a different availability zone, see this guide.

Getting a list of cluster hostsGetting a list of cluster hosts

Management console
CLI
REST API
gRPC API
  1. Navigate to the folder dashboard and select Managed Service for MongoDB.
  2. Click the name of the Managed Service for MongoDB cluster.
  3. Select the Hosts tab.

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 get a list of Managed Service for MongoDB cluster hosts, run this command:

yc managed-mongodb host list \
  --cluster-name <cluster_name>

Result:

+----------------------------+----------------------+--------+------------+--------------+----------+---------------+-----------+
|           NAME             |      CLUSTER ID      |  TYPE  | SHARD NAME |     ROLE     |  HEALTH  |    ZONE ID    | PUBLIC IP |
+----------------------------+----------------------+--------+------------+--------------+----------+---------------+-----------+
| rc1b...mdb.yandexcloud.net | c9qp71dk1q1w******** | MONGOD | rs01       | PRIMARY      | ALIVE    | ru-central1-b | false     |
| rc1a...mdb.yandexcloud.net | c9qp71dk1q1w******** | MONGOD | rs01       | SECONDARY    | ALIVE    | ru-central1-a | false     |
+----------------------------+----------------------+--------+------------+--------------+----------+---------------+-----------+

You can request the Managed Service for MongoDB cluster name with a 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.ListHosts method and send the following request, e.g., via cURL:

    curl \
        --request GET \
        --header "Authorization: Bearer $IAM_TOKEN" \
        --url 'https://mdb.api.cloud.yandex.net/managed-mongodb/v1/clusters/<cluster_ID>/hosts'
    

    You can request the cluster ID with the list of clusters in the folder.

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

    You can request the cluster ID with the list of clusters in the folder.

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

Adding a hostAdding a host

The number of hosts in Managed Service for MongoDB clusters is limited by the CPU and RAM quotas available to DB clusters in your cloud. To check the resources currently in use, open the Quotas page and find Managed Service for MongoDB.

You can add different types of hosts to a Managed Service for MongoDB cluster. Their number depends on the sharding type:

Sharding type MONGOD MONGOINFRA MONGOS MONGOCFG
No sharding ⩾ 1 — — —
Standard ⩾ 1 ⩾ 3 — —
Advanced ⩾ 1 — ⩾ 2 ⩾ 3
Management console
CLI
Terraform
REST API
gRPC API

To add a host to your Managed Service for MongoDB cluster:

  1. Navigate to the folder dashboard and select Managed Service for MongoDB.
  2. Click the name of the Managed Service for MongoDB cluster you need and go to the Hosts tab.
  3. Click Create host.
  4. Specify the host parameters:
    • Availability zone.
    • Subnet (if the required subnet is not on the list, create it).
    • Select Public access if the host must be accessible from outside Yandex Cloud.
    • Host type and shard name, if sharding is enabled for the Managed Service for MongoDB cluster.
  5. Click Save.

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 add a host to your Managed Service for MongoDB cluster:

  1. Request a list of Managed Service for MongoDB cluster subnets to select a subnet for the new host:

    yc vpc subnet list
    

    Result:

    +----------------------+-----------+-----------------------+---------------+------------------+
    |          ID          |   NAME    |       NETWORK ID      |       ZONE    |      RANGE       |
    +----------------------+-----------+-----------------------+---------------+------------------+
    | b0cl69a2b4c6******** | default-d | enp6rq72rndgr******** | ru-central1-d | [172.16.0.0/20]  |
    | e2lkj9qwe762******** | default-b | enp6rq72rndgr******** | ru-central1-b | [10.10.0.0/16]   |
    | e9b0ph42bn96******** | a-2       | enp6rq72rndgr******** | ru-central1-a | [172.16.32.0/20] |
    | e9b9v22r88io******** | default-a | enp6rq72rndgr******** | ru-central1-a | [172.16.16.0/20] |
    +----------------------+-----------+-----------------------+---------------+------------------+
    

    If the required subnet is not in the list, create it.

  2. View a description of the CLI command for adding a host:

    yc managed-mongodb host add --help
    
  3. Run the add host command:

    yc managed-mongodb host add \
      --cluster-name <cluster_name> \
      --host zone-id=<availability_zone>,`
            `subnet-id=<subnet_ID>,`
            `assign-public-ip=<public_access>,`
            `hidden=<hide_host>,`
            `secondary-delay-secs=<replica_lag_in_seconds>,`
            `priority=<host_priority>
    

    Where:

    • --cluster-name: Cluster name. You can get it with the list of clusters in a folder.
    • --host: Host parameters:
      • zone-id: Availability zone.
      • subnet-id: Subnet ID. You need to specify it if the availability zone contains more than one subnet; otherwise, Managed Service for MongoDB will automatically select the only subnet there is.
      • assign-public-ip: Internet access to the host via a public IP address, true or false.
      • hidden: Hide host, true or false. If the host is hidden, only direct connections will be able to read from it (for example, to make backups from it without adding load to the cluster).
      • secondary-delay-secs: Replica's lag behind the master in seconds. It can be useful for data recovery in case of invalid operations.
      • priority: Host priority for assignment as a master.

    Managed Service for MongoDB will run the add host operation.

To add a host to your Managed Service for MongoDB cluster:

  1. Open the current Terraform configuration file that defines your infrastructure.

    For more information about creating this file, see Creating clusters.

  2. Add the following to the Managed Service for MongoDB cluster description:

    • Resources corresponding to the sharding type, if you are adding a host to a sharded cluster:
      • resources_mongoinfra for standard sharding.
      • resources_mongos and resources_mongocfg for advanced sharding.
    • host block.
    resource "yandex_mdb_mongodb_cluster" "<cluster_name>" {
      ...
      resources_mongod {
        resource_preset_id = "<host_class>"
        disk_type_id       = "<disk_type>"
        disk_size          = <storage_size_in_GB>
      }
    
      resources_mongoinfra { # Add for standard sharding.
        resource_preset_id = "<host_class>"
        disk_type_id       = "<disk_type>"
        disk_size          = <storage_size_in_GB>
      }
    
      resources_mongos { # Add for advanced sharding.
        resource_preset_id = "<host_class>"
        disk_type_id       = "<disk_type>"
        disk_size          = <storage_size_in_GB>
      }
    
      resources_mongocfg { # Add for advanced sharding.
        resource_preset_id = "<host_class>"
        disk_type_id       = "<disk_type>"
        disk_size          = <storage_size_in_GB>
      }
    
      host {
        role             = "<replica_type>"
        zone_id          = "<availability_zone>"
        subnet_id        = "<subnet_ID>"
        assign_public_ip = <public_access>
        shard_name       = "<shard_name>"
        type             = "<host_type>"
        host_parameters {
          hidden               = <hide_host>
          secondary_delay_secs = <replica_lag_in_seconds>
          priority             = <host_priority>
        }
        ...
      }
    }
    

    Where:

    • host: Host parameters:
      • role: Replica type (PRIMARY or SECONDARY).
      • zone_id: Availability zone.
      • subnet_id: ID of a subnet in the selected availability zone.
      • assign_public_ip: Public access to the host, true or false.
      • shard_name: Shard name in a sharded cluster.
      • type: Host type in a sharded cluster, MONGOD, MONGOINFRA, MONGOS, or MONGOCFG.
      • host_parameters: Additional host parameters:
        • hidden: Hide host, true or false. If the host is hidden, only direct connections will be able to read from it (for example, to make backups from it without adding load to the cluster).
        • secondary_delay_secs: Replica's lag behind the master in seconds. It can be useful for data recovery in case of invalid operations.
        • priority: Host priority for assignment as a master.
  3. Make sure the settings are correct.

    1. In the command line, navigate to the directory that contains the current Terraform configuration files defining the infrastructure.

    2. Run this command:

      terraform validate
      

      Terraform will show any errors found in your configuration files.

  4. Confirm updating the resources.

    1. Run this command to view the planned changes:

      terraform plan
      

      If you described the configuration correctly, the terminal will display a list of the resources to update and their parameters. This is a verification step that does not apply changes to your resources.

    2. If everything looks correct, apply the changes:

      1. Run this command:

        terraform apply
        
      2. Confirm updating the resources.

      3. Wait for the operation to complete.

For more information, see the Terraform provider documentation.

Timeouts

The Terraform provider sets the following timeouts for Managed Service for MongoDB cluster operations:

  • Creating a cluster, including by restoring one from a backup: 30 minutes.
  • Editing a cluster: 60 minutes.

Operations exceeding the set timeout are interrupted.

How do I change these limits?

Add the timeouts block to the cluster description, for example:

resource "yandex_mdb_mongodb_cluster" "<cluster_name>" {
  ...
  timeouts {
    create = "1h30m" # An hour and a half
    update = "2h"    # Two hours
  }
}
  1. Get an IAM token for API authentication and put it into the environment variable:

    export IAM_TOKEN="<IAM_token>"
    
  2. Use the Cluster.AddHosts 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>/hosts:batchCreate' \
        --data '{
                  "hostSpecs": [
                    {
                      "zoneId": "<availability_zone>",
                      "subnetId": "<subnet_ID>",
                      "assignPublicIp": <public_access_to_host>,
                      "type": "<host_type>",
                      "shardName": "<shard_name>",
                      "hidden": <hide_host>,
                      "secondaryDelaySecs": "<replica_lag_in_seconds>",
                      "priority": "<host_priority>",
                      "tags": "<host_tags>"
                    }
                  ]
                }'
    

    Where hostSpecs sets the host parameters:

    • zoneId: Availability zone.
    • subnetId: Subnet ID.
    • assignPublicIp: Internet access to the host via a public IP address, true or false.
    • type: Host type in a sharded cluster, MONGOD, MONGOINFRA, MONGOS, or MONGOCFG. For a non-sharded cluster, use MONGOD.
    • shardName: Shard name in a sharded cluster.
    • hidden: Hide host, true or false. If the host is hidden, only direct connections will be able to read from it (for example, to make backups from it without adding load to the cluster).
    • secondaryDelaySecs: Replica's lag behind the master in seconds. It can be useful for data recovery in case of invalid operations.
    • priority: * hidden: Hide host, true or false. If the host is hidden, only direct connections will be able to read from it (for example, to make backups from it without adding load to the cluster).
    • secondaryDelaySecs: Replica's lag behind the master in seconds. It can be useful for data recovery in case of invalid operations.
    • priority: Host priority for assignment as a master.
    • tags: Host tags.

    You can request the cluster ID with the list of clusters in the folder.

  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.AddHosts 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_specs": [
                {
                  "zone_id": "<availability_zone>",
                  "subnet_id": "<subnet_ID>",
                  "assign_public_ip": <public_access_to_host>,
                  "type": "<host_type>",
                  "shard_name": "<shard_name>",
                  "hidden": <hide_host>,
                  "secondary_delay_secs": "<replica_lag_in_seconds>",
                  "priority": "<host_priority>",
                  "tags": "<host_tags>"
                }
              ]
            }' \
        mdb.api.cloud.yandex.net:443 \
        yandex.cloud.mdb.mongodb.v1.ClusterService.AddHosts
    

    Where host_specs sets the host parameters:

    • zone_id: Availability zone.
    • subnet_id: Subnet ID.
    • assign_public_ip: Internet access to the host via a public IP address, true or false.
    • type: Host type in a sharded cluster, MONGOD, MONGOINFRA, MONGOS, or MONGOCFG. For a non-sharded cluster, use MONGOD.
    • shard_name: Shard name in a sharded cluster.
    • hidden: Hide host, true or false. If the host is hidden, only direct connections will be able to read from it (for example, to make backups from it without adding load to the cluster).
    • secondaryDelaySecs: Replica's lag behind the master in seconds. It can be useful for data recovery in case of invalid operations.
    • priority: Host priority for assignment as a master.
    • tags: Host tags.

    You can request the cluster ID with the list of clusters in the folder.

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

Warning

If you cannot connect to the host you added, check that the Managed Service for MongoDB cluster security group is configured correctly for the host's subnet.

Changing a hostChanging a host

CLI
Terraform
REST API
gRPC API

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 the parameters of a host in a cluster, run the command below:

yc managed-mongodb host update \
  --cluster-name <cluster_name> \
  --host hostname=<host_name>,`
        `assign-public-ip=<public_access_to_host>,`
        `hidden=<hide_host>,`
        `secondary-delay-secs=<replica_lag_in_seconds>,`
        `priority=<host_priority>

Where:

  • --cluster-name: Cluster name. You can get it with the list of clusters in a folder.
  • --host: Host parameters:
    • hostname: Name of the host you are editing. You can request it with the list of hosts in the cluster.
    • assign-public-ip: Internet access to the host via a public IP address, true or false.
    • hidden: Hide host, true or false. If the host is hidden, only direct connections will be able to read from it (for example, to make backups from it without adding load to the cluster).
    • secondary-delay-secs: Replica's lag behind the master in seconds. It can be useful for data recovery in case of invalid operations.
    • priority: Host priority for assignment as a master.

To change the parameters of the cluster host:

  1. Open the current Terraform configuration file that defines your infrastructure.

    For more information about creating this file, see Creating clusters.

    For a complete list of available Managed Service for PostgreSQL cluster configuration fields, see the Terraform provider documentation.

  2. In the Managed Service for PostgreSQL cluster description, change the attributes of the host block corresponding to the host you are updating.

    resource "yandex_mdb_mongodb_cluster" "<cluster_name>" {
      ...
      host {
        assign_public_ip = <public_access_to_host>
        host_parameters {
          hidden               = <hide_host>
          secondary_delay_secs = <replica_lag_in_seconds>
          priority             = <host_priority>
        }
      }
    }
    

Where:

  • assign_public_ip: Internet access to the host via a public IP address, true or false.
  • host_parameters: Additional host parameters:
    • hidden: Hide host, true or false. If the host is hidden, only direct connections will be able to read from it (for example, to make backups from it without adding load to the cluster).
    • secondary_delay_secs: Replica's lag behind the master in seconds. It can be useful for data recovery in case of invalid operations.
    • priority: Host priority for assignment as a master.
  1. Make sure the settings are correct.

    1. In the command line, navigate to the directory that contains the current Terraform configuration files defining the infrastructure.

    2. Run this command:

      terraform validate
      

      Terraform will show any errors found in your configuration files.

  2. Confirm updating the resources.

    1. Run this command to view the planned changes:

      terraform plan
      

      If you described the configuration correctly, the terminal will display a list of the resources to update and their parameters. This is a verification step that does not apply changes to your resources.

    2. If everything looks correct, apply the changes:

      1. Run this command:

        terraform apply
        
      2. Confirm updating the resources.

      3. Wait for the operation to complete.

    Timeouts

    The Terraform provider sets the following timeouts for Managed Service for MongoDB cluster operations:

    • Creating a cluster, including by restoring one from a backup: 30 minutes.
    • Editing a cluster: 60 minutes.

    Operations exceeding the set timeout are interrupted.

    How do I change these limits?

    Add the timeouts block to the cluster description, for example:

    resource "yandex_mdb_mongodb_cluster" "<cluster_name>" {
      ...
      timeouts {
        create = "1h30m" # An hour and a half
        update = "2h"    # Two hours
      }
    }
    
  1. Get an IAM token for API authentication and put it into the environment variable:

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

    Warning

    The API method will assign default values to all the parameters of the object you are modifying unless you explicitly provide them in your request. To avoid this, list the settings you want to change in the updateMask parameter as a single comma-separated string.

    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>/hosts:batchUpdate' \
      --data '{
                "updateHostSpecs": [
                  {
                    "updateMask": "hostName,assignPublicIp,hidden,secondaryDelaySecs,priority",
                    "hostName": "<host_name>",
                    "assignPublicIp": <public_access_to_host>,
                    "hidden": <hide_host>,
                    "secondaryDelaySecs": "<replica_lag_in_seconds>",
                    "priority": "<host_priority>"
                  }
                ]
              }'
    

    Where updateHostSpecs sets the host parameters:

    • updateMask: List of parameters to update as a single string, separated by commas.
    • hostName: Name of the host you are editing. You can request it with the list of hosts in the cluster.
    • assignPublicIp: Internet access to the host via a public IP address, true or false.
    • hidden: Hide host, true or false. If the host is hidden, only direct connections will be able to read from it (for example, to make backups from it without adding load to the cluster).
    • secondaryDelaySecs: Replica's lag behind the master in seconds. It can be useful for data recovery in case of invalid operations.
    • priority: Host priority for assignment as a master.

    You can request the cluster ID with the list of clusters in the folder.

  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/UpdateHosts call and send the following request, e.g., via gRPCurl:

    Warning

    The API method will assign default values to all the parameters of the object you are modifying unless you explicitly provide them in your request. To avoid this, list the settings you want to change in the update_mask parameter as an array of paths[] strings.

    Format for listing settings
    "update_mask": {
        "paths": [
            "<setting_1>",
            "<setting_2>",
            ...
            "<setting_N>"
        ]
    }
    
    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>",
            "update_host_specs": [
              {
                "update_mask": {
                    "paths": [
                      "assign_public_ip",
                      "hidden",
                      "secondary_delay_secs",
                      "priority"
                    ]
                },
                "host_name": "<host_name>",
                "assign_public_ip": <public_access_to_host>,
                "hidden": <hide_host>,
                "secondary_delay_secs": "<replica_lag_in_seconds>",
                "priority": "<host_priority>"
              }
            ]
          }' \
      mdb.api.cloud.yandex.net:443 \
      yandex.cloud.mdb.mongodb.v1.ClusterService.UpdateHosts
    

    Where update_host_specs sets the host parameters:

    • update_mask: List of parameters to update as a single string, separated by commas.
    • host_name: Name of the host you are editing. You can request it with the list of hosts in the cluster.
    • assign_public_ip: Internet access to the host via a public IP address, true or false.
    • hidden: Hide host, true or false. If the host is hidden, only direct connections will be able to read from it (for example, to make backups from it without adding load to the cluster).
    • secondary_delay_secs: Replica's lag behind the master in seconds. It can be useful for data recovery in case of invalid operations.
    • priority: Host priority for assignment as a master.

    You can request the cluster ID with the list of clusters in the folder.

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

Removing a hostRemoving a host

You can remove a MONGOD host from a Managed Service for MongoDB cluster if it is not the only host in it. To replace a single host, first create a new host and then remove the old one.

If the host you are removing is a primary one, Managed Service for MongoDB will automatically select a new primary replica.

From a sharded Managed Service for MongoDB cluster, you may remove the MONGOS, MONGOCFG, or MONGOINFRA hosts that exceed the minimum number needed for sharding.

Management console
CLI
Terraform
REST API
gRPC API

To remove a host from a Managed Service for MongoDB cluster:

  1. Navigate to the folder dashboard and select Managed Service for MongoDB.
  2. Click the name of the Managed Service for MongoDB cluster you need and select the Hosts tab.
  3. Click in the host's row and select Delete.
  4. In the window that opens, check Delete host and click Confirm.

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 remove a host from the Managed Service for MongoDB cluster, run:

yc managed-mongodb host delete <host_name>
  --cluster-name <cluster_name>

You can request the host name with a list of Managed Service for MongoDB cluster hosts and the cluster name with a list of clusters in the folder.

To remove a host from a Managed Service for MongoDB cluster:

  1. Open the current Terraform configuration file that defines your infrastructure.

    For more information about creating this file, see Creating clusters.

  2. Delete the corresponding host block from the Managed Service for MongoDB cluster description.

  3. Make sure the settings are correct.

    1. In the command line, navigate to the directory that contains the current Terraform configuration files defining the infrastructure.

    2. Run this command:

      terraform validate
      

      Terraform will show any errors found in your configuration files.

  4. Type yes and press Enter.

    1. Run this command to view the planned changes:

      terraform plan
      

      If you described the configuration correctly, the terminal will display a list of the resources to update and their parameters. This is a verification step that does not apply changes to your resources.

    2. If everything looks correct, apply the changes:

      1. Run this command:

        terraform apply
        
      2. Confirm updating the resources.

      3. Wait for the operation to complete.

For more information, see the Terraform provider documentation.

Timeouts

The Terraform provider sets the following timeouts for Managed Service for MongoDB cluster operations:

  • Creating a cluster, including by restoring one from a backup: 30 minutes.
  • Editing a cluster: 60 minutes.

Operations exceeding the set timeout are interrupted.

How do I change these limits?

Add the timeouts block to the cluster description, for example:

resource "yandex_mdb_mongodb_cluster" "<cluster_name>" {
  ...
  timeouts {
    create = "1h30m" # An hour and a half
    update = "2h"    # Two hours
  }
}
  1. Get an IAM token for API authentication and put it into the environment variable:

    export IAM_TOKEN="<IAM_token>"
    
  2. Use the Cluster.DeleteHosts 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>/hosts:batchDelete' \
        --data '{
                  "hostNames": [
                    "<host_name>"
                  ]
                }'
    

    Where hostNames is an array with the names of hosts to delete. To find out the host name, get a list of hosts in the cluster.

    You can request the cluster ID with the list of clusters in the folder.

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

    Where host_names is an array with the names of hosts to delete. To find out the host name, get a list of hosts in the cluster.

    You can request the cluster ID with the list of clusters in the folder.

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

Starting host resyncStarting host resync

To resync a host with other replicas in the Managed Service for MongoDB cluster or shard, run forced resync. The operation can be applied to only one MONGOD host at a time and only for Managed Service for MongoDB clusters with more than two replicas, regardless of the host class and type. Resync also lets you remove the collections and documents that were marked as deleted from the host's storage.

During this operation:

  1. The host stops accepting write requests. If the host was a PRIMARY replica, Managed Service for MongoDB will try to make it a SECONDARY replica. If the operation fails, it is aborted.

  2. The MongoDB instance on the host stops, and all data is deleted.

  3. The MongoDB instance restarts and downloads data from replica hosts again.

  4. Once the host has synced with other replicas in the Managed Service for MongoDB cluster, it becomes a secondary replica.

    Note

    • During syncing, the host cannot fully respond to any request, because it has only a part of the Managed Service for MongoDB cluster data.
    • Estimated sync rate: 300 GB per day or more.
Management console
CLI
REST API
gRPC API

To forcibly resync a host:

  1. Navigate to the folder dashboard and select Managed Service for MongoDB.
  2. Click the name of the Managed Service for MongoDB cluster you need and select the Hosts tab.
  3. Click in the host's row and select Resynchronize.

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 forcibly resync a host, run the following command:

yc managed-mongodb hosts resetup <host_name>
   --cluster-name <cluster_name>

You can get the host name with a list of hosts in the folder. You can request the Managed Service for MongoDB cluster name with a 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.ResetupHosts 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>:resetupHosts' \
        --data '{
                  "hostNames": [
                    "<host_name>"
                  ]
                }'
    

    Where hostNames is an array with the names of hosts to re-sync. To find out the host name, get a list of hosts in the cluster.

    You can request the cluster ID with the list of clusters in the folder.

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

    Where host_names is an array with the names of hosts to re-sync. To find out the host name, get a list of hosts in the cluster.

    You can request the cluster ID with the list of clusters in the folder.

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

Restarting a hostRestarting a host

You can manually restart Managed Service for MongoDB cluster hosts.

Restarting a host may make a Managed Service for MongoDB cluster or shard temporarily unavailable:

  • If there is a single host in the cluster.
  • If the host is the primary replica.

When the primary replica is restarted, there is no automatic switch-over. To make sure the Managed Service for MongoDB cluster remains available, switch the cluster's primary replica before it is restarted.

Note

You can only restart one host at a time.

Management console
CLI
REST API
gRPC API

To restart a host:

  1. Navigate to the folder dashboard and select Managed Service for MongoDB.
  2. Click the name of the Managed Service for MongoDB cluster you need and select the Hosts tab.
  3. Click in the host's row and select Restart.
  4. Confirm the host restart.

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 restart a host, run the command:

yc managed-mongodb hosts restart <host_name> \
  --cluster-name <cluster_name>
  1. Get an IAM token for API authentication and put it into the environment variable:

    export IAM_TOKEN="<IAM_token>"
    
  2. Use the Cluster.RestartHosts 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>:restartHosts' \
        --data '{
                  "hostNames": [
                    "<host_name>"
                  ]
                }'
    

    Where hostNames is an array with the names of hosts to restart. To find out the host name, get a list of hosts in the cluster.

    You can request the cluster ID with the list of clusters in the folder.

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

    Where host_names is an array with the names of hosts to restart. To find out the host name, get a list of hosts in the cluster.

    You can request the cluster ID with the list of clusters in the folder.

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

Was the article helpful?

Previous
Stopping and starting a cluster
Next
Migrating hosts to a different availability zone
© 2025 Direct Cursus Technology L.L.C.