[Yandex Cloud documentation](../../index.md) > [Yandex StoreDoc](../index.md) > [Step-by-step guides](index.md) > Clusters > Managing cluster hosts

# Managing Yandex StoreDoc cluster hosts

You can add or remove [cluster hosts](../concepts/index.md), restart host synchronization, and [manage Yandex StoreDoc cluster settings](update.md). To learn how to migrate your cluster hosts to a different availability zone, see [this guide](host-migration.md).

## Getting a list of cluster hosts {#list-hosts}

{% list tabs group=instructions %}

- Management console {#console}

  1. Open the [folder dashboard](https://console.yandex.cloud).
  1. Navigate to **Yandex StoreDoc**.
  1. Click the name of the Yandex StoreDoc cluster.
  1. Select the **Hosts** tab.

- CLI {#cli}

  If you do not have the Yandex Cloud CLI yet, [install and initialize it](../../cli/quickstart.md#install).

  The folder used by default is the one specified when [creating](../../cli/operations/profile/profile-create.md) 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 get the list of Yandex StoreDoc cluster hosts, run this command:

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

  Result:

  
  ```text
  +----------------------------+----------------------+--------+------------+--------------+----------+---------------+-----------+
  |           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 get the Yandex StoreDoc cluster name from the [list of clusters in your folder](cluster-list.md#list-clusters).

- REST API {#api}

    1. [Get an IAM token for API authentication](../api-ref/authentication.md) and put it into an environment variable:

       ```bash
       export IAM_TOKEN="<IAM_token>"
       ```

    1. Call the [Cluster.ListHosts](../api-ref/Cluster/listHosts.md) method, e.g., via the following [cURL](https://curl.se/) request:

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

        You can get the cluster ID from the [list of clusters in your folder](cluster-list.md#list-clusters).

    1. Check the [server response](../api-ref/Cluster/listHosts.md#yandex.cloud.mdb.mongodb.v1.ListClusterHostsResponse) to make sure your request was successful.

- gRPC API {#grpc-api}

    1. [Get an IAM token for API authentication](../api-ref/authentication.md) and put it into an environment variable:

        ```bash
        export IAM_TOKEN="<IAM_token>"
        ```

    1. Clone the [cloudapi](https://github.com/yandex-cloud/cloudapi) repository:
       
       ```bash
       cd ~/ && git clone --depth=1 https://github.com/yandex-cloud/cloudapi
       ```
       
       Below, we assume that the repository contents reside in the `~/cloudapi/` directory.

    1. Call the [ClusterService.ListHosts](../api-ref/grpc/Cluster/listHosts.md) method, e.g., via the following [gRPCurl](https://github.com/fullstorydev/grpcurl) request:

        ```bash
        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 get the cluster ID with the [list of clusters in the folder](cluster-list.md#list-clusters).

    1. Check the [server response](../api-ref/grpc/Cluster/listHosts.md#yandex.cloud.mdb.mongodb.v1.ListClusterHostsResponse) to make sure your request was successful.    

{% endlist %}

## Adding a host {#add-host}

The number of hosts in Yandex StoreDoc clusters is limited by the CPU and memory quotas allocated to the database clusters in your[cloud](../../resource-manager/concepts/resources-hierarchy.md#cloud). To review current resource usage, open the [Quotas](https://console.yandex.cloud/cloud?section=quotas) page and find the **Yandex StoreDoc** section.

You can add hosts of different types to your Yandex StoreDoc cluster. Their number depends on the [sharding type](../concepts/sharding.md#shard-management):

{#hosts-table}

Sharding type | MONGOD | MONGOINFRA | MONGOS | MONGOCFG
--- | --- | --- | --- | ---
No sharding | ⩾ 1 | — | — | —
Standard | ⩾ 1 | ⩾ 3 | — | —
Advanced | ⩾ 1 | — | ⩾ 2 | ⩾ 3

{% list tabs group=instructions %}

- Management console {#console}

  To add a host to your Yandex StoreDoc cluster:
  1. Open the [folder dashboard](https://console.yandex.cloud).
  1. Navigate to **Yandex StoreDoc**.
  1. Click the name of your Yandex StoreDoc cluster and open the **Hosts** tab.
  1. Click **Create host**.
  1. Specify the following host settings:
     * [Availability zone](../../overview/concepts/geo-scope.md).

     
     * [Subnet](../../vpc/concepts/network.md#subnet) (if the required subnet is not on the list, create it).     

     * To make the host accessible from outside Yandex Cloud, select **Public access**.


     * Host type and shard name, if sharding is enabled for the Yandex StoreDoc cluster.
  1. Click **Save**.

- CLI {#cli}

  If you do not have the Yandex Cloud CLI yet, [install and initialize it](../../cli/quickstart.md#install).

  The folder used by default is the one specified when [creating](../../cli/operations/profile/profile-create.md) 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 add a host to your Yandex StoreDoc cluster:

  
  1. To choose a [subnet](../../vpc/concepts/network.md#subnet) for your new host, first get the list of subnets in the Yandex StoreDoc cluster:

     ```bash
     yc vpc subnet list
     ```

     Result:

     ```text
     +----------------------+-----------+-----------------------+---------------+------------------+
     |          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 on the list, create it.


  1. See the description of the CLI command for adding new hosts:

     ```bash
     yc managed-mongodb host add --help
     ```

  1. Run this command to add a host:

      
      ```bash
      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 from the [list of clusters in your folder](cluster-list.md#list-clusters).
      * `--host`: Host settings:
          * `zone-id`: [Availability zone](../../overview/concepts/geo-scope.md).

          
          * `subnet-id`: [Subnet ID](../../vpc/concepts/network.md#subnet). You should specify the subnet ID if the [availability zone](../../overview/concepts/geo-scope.md) contains more than one subnet; otherwise, Yandex StoreDoc will automatically select the only subnet.
          * `assign-public-ip`: Internet access to the host via a public IP address, `true` or `false`.


          * `hidden`: Determines whether the host is hidden, `true` or `false`. A hidden host is still accessible for read operations, but only through direct connections. This can be useful, for example, for making backups without adding extra load to the cluster.
          * `secondary-delay-secs`: Replica's lag behind the master in seconds. This setting can be useful for data recovery after operational errors.
          * `priority`: [Host priority for master promotion](../concepts/replication.md#master-failover).

      Yandex StoreDoc will start the host addition process.


- Terraform {#tf}

  To add a host to your Yandex StoreDoc cluster:
  1. Open the current Terraform configuration file with the infrastructure plan.

     To learn how to create this file, see [Creating a cluster](cluster-create.md).
  1. Add the following to the Yandex StoreDoc cluster description:
     * Required resources, based on 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.

     ```hcl
     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 settings:
       * `role`: Replica type, `PRIMARY` or `SECONDARY`.
       * `zone_id`: Availability zone.
       * `subnet_id`: ID of the 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 settings:
           * `hidden`: Determines whether the host is hidden, `true` or `false`. A hidden host is still accessible for read operations, but only through direct connections. This can be useful, for example, for making backups without adding extra load to the cluster.
           * `secondary_delay_secs`: Replica's lag behind the master in seconds. This setting can be useful for data recovery after operational errors.
           * `priority`: [Host priority for master promotion](../concepts/replication.md#master-failover).

  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.
     1. Run this command:
     
        ```bash
        terraform validate
        ```
     
        Terraform will show any errors found in your configuration files.

  1. Confirm updating the resources.

     1. Run this command to view the planned changes:
     
        ```bash
        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.
     
     1. If everything looks correct, apply the changes:
        1. Run this command:
     
           ```bash
           terraform apply
           ```
     
        1. Confirm updating the resources.
        1. Wait for the operation to complete.

  For more information, see [this Terraform provider guide](../../terraform/resources/mdb_mongodb_cluster.md).

  {% note warning "Timeouts" %}
  
  The Terraform provider sets the following timeouts for Yandex StoreDoc 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.
  
  {% cut "How do I change these limits?" %}
  
  Add the `timeouts` block to the cluster description, for example:
  
  ```hcl
  resource "yandex_mdb_mongodb_cluster" "<cluster_name>" {
    ...
    timeouts {
      create = "1h30m" # An hour and a half
      update = "2h"    # Two hours
    }
  }
  ```
  
  {% endcut %}
  
  {% endnote %}


- REST API {#api}

  1. [Get an IAM token for API authentication](../api-ref/authentication.md) and put it into an environment variable:

      ```bash
      export IAM_TOKEN="<IAM_token>"
      ```

  1. Call the [Cluster.AddHosts](../api-ref/Cluster/addHosts.md) method, e.g., via the following [cURL](https://curl.se/) request:

      
      ```bash
      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` are the host settings:

      * `zoneId`: [Availability zone](../../overview/concepts/geo-scope.md).

      
      * `subnetId`: [Subnet ID](../../vpc/concepts/network.md#subnet).
      * `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`: Determines whether the host is hidden, `true` or `false`. A hidden host is still accessible for read operations, but only through direct connections. This can be useful, for example, for making backups without adding extra load to the cluster.
      * `secondaryDelaySecs`: Replica's lag behind the master in seconds. This setting can be useful for data recovery after operational errors.
      * `priority`: Determines whether the host is hidden, `true` or `false`. A hidden host is still accessible for read operations, but only through direct connections. This can be useful, for example, for making backups without adding extra load to the cluster.
      * `secondaryDelaySecs`: Replica's lag behind the master in seconds. This setting can be useful for data recovery after operational errors.
      * `priority`: [Host priority for master promotion](../concepts/replication.md#master-failover).
      * `tags`: Host tags.

      You can get the cluster ID from the [list of clusters in your folder](cluster-list.md#list-clusters).

  1. Check the [server response](../api-ref/Cluster/addHosts.md#yandex.cloud.operation.Operation) to make sure your request was successful.

- gRPC API {#grpc-api}

  1. [Get an IAM token for API authentication](../api-ref/authentication.md) and put it into an environment variable:

      ```bash
      export IAM_TOKEN="<IAM_token>"
      ```

  1. Clone the [cloudapi](https://github.com/yandex-cloud/cloudapi) repository:
     
     ```bash
     cd ~/ && git clone --depth=1 https://github.com/yandex-cloud/cloudapi
     ```
     
     Below, we assume that the repository contents reside in the `~/cloudapi/` directory.
  1. Call the [ClusterService.AddHosts](../api-ref/grpc/Cluster/addHosts.md) method, e.g., via the following [gRPCurl](https://github.com/fullstorydev/grpcurl) request:

      
      ```bash
      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` are the host settings:

      * `zone_id`: [Availability zone](../../overview/concepts/geo-scope.md).

      
      * `subnet_id`: [Subnet ID](../../vpc/concepts/network.md#subnet).
      * `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`: Determines whether the host is hidden, `true` or `false`. A hidden host is still accessible for read operations, but only through direct connections. This can be useful, for example, for making backups without adding extra load to the cluster.
      * `secondaryDelaySecs`: Replica's lag behind the master in seconds. This setting can be useful for data recovery after operational errors.
      * `priority`: [Host priority for master promotion](../concepts/replication.md#master-failover).
      * `tags`: Host tags.

      You can get the cluster ID with the [list of clusters in the folder](cluster-list.md#list-clusters).

  1. Check the [server response](../api-ref/grpc/Cluster/addHosts.md#yandex.cloud.operation.Operation) to make sure your request was successful.

{% endlist %}


{% note warning %}

If you cannot [connect](connect/index.md) to the new host, check the Yandex StoreDoc cluster‘s [security group](../concepts/network.md#security-groups) settings for its subnet.

{% endnote %}


## Updating a host {#update}

{% list tabs group=instructions %}

- CLI {#cli}

    If you do not have the Yandex Cloud CLI yet, [install and initialize it](../../cli/quickstart.md#install).

    The folder used by default is the one specified when [creating](../../cli/operations/profile/profile-create.md) 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 update the cluster host’s settings, run the following command:

    
    ```bash
    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 from the [list of clusters in your folder](cluster-list.md#list-clusters).
    * `--host`: Host settings:
        * `hostname`: Target host name. You can get it from the [list of your cluster hosts](#list).

        
        * `assign-public-ip`: Internet access to the host via a public IP address, `true` or `false`.


        * `hidden`: Determines whether the host is hidden, `true` or `false`. A hidden host is still accessible for read operations, but only through direct connections. This can be useful, for example, for making backups without adding extra load to the cluster.
        * `secondary-delay-secs`: Replica's lag behind the master in seconds. This setting can be useful for data recovery after operational errors.
        * `priority`: [Host priority for master promotion](../concepts/replication.md#master-failover).


- Terraform {#tf}

    To change the cluster host settings:

    1. Open the current Terraform configuration file with the infrastructure plan.

        To learn how to create this file, see [Creating a cluster](cluster-create.md).

        For the complete list of configurable Managed Service for PostgreSQL cluster fields, see [this Terraform provider guide](../../terraform/resources/mdb_postgresql_cluster.md).

    1. In the Managed Service for PostgreSQL cluster description, change the attributes of the `host` section referring to the host you want to update.

        ```hcl
        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 settings:
        * `hidden`: Determines whether the host is hidden, `true` or `false`. A hidden host is still accessible for read operations, but only through direct connections. This can be useful, for example, for making backups without adding extra load to the cluster.
        * `secondary_delay_secs`: Replica's lag behind the master in seconds. This setting can be useful for data recovery after operational errors.
        * `priority`: [Host priority for master promotion](../concepts/replication.md#master-failover).

    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.
        1. Run this command:
        
           ```bash
           terraform validate
           ```
        
           Terraform will show any errors found in your configuration files.

    1. Confirm updating the resources.

        1. Run this command to view the planned changes:
        
           ```bash
           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.
        
        1. If everything looks correct, apply the changes:
           1. Run this command:
        
              ```bash
              terraform apply
              ```
        
           1. Confirm updating the resources.
           1. Wait for the operation to complete.

        {% note warning "Timeouts" %}
        
        The Terraform provider sets the following timeouts for Yandex StoreDoc 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.
        
        {% cut "How do I change these limits?" %}
        
        Add the `timeouts` block to the cluster description, for example:
        
        ```hcl
        resource "yandex_mdb_mongodb_cluster" "<cluster_name>" {
          ...
          timeouts {
            create = "1h30m" # An hour and a half
            update = "2h"    # Two hours
          }
        }
        ```
        
        {% endcut %}
        
        {% endnote %}


- REST API {#api}

    1. [Get an IAM token for API authentication](../api-ref/authentication.md) and put it into an environment variable:

        ```bash
        export IAM_TOKEN="<IAM_token>"
        ```

    1. Call the [Cluster.updateHosts](../api-ref/Cluster/updateHosts.md) method, e.g., via the following [cURL](https://curl.se/) request:

        {% note 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.
        
        {% endnote %}

        
        ```bash
        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` are the host settings:

        * `updateMask`: Comma-separated list of settings you want to update.
        * `hostName`: Target host name. You can get it from the [list of your cluster hosts](#list-hosts).

        
        * `assignPublicIp`: Internet access to the host via a public IP address, `true` or `false`.


        * `hidden`: Determines whether the host is hidden, `true` or `false`. A hidden host is still accessible for read operations, but only through direct connections. This can be useful, for example, for making backups without adding extra load to the cluster.
        * `secondaryDelaySecs`: Replica's lag behind the master in seconds. This setting can be useful for data recovery after operational errors.
        * `priority`: [Host priority for master promotion](../concepts/replication.md#master-failover).

        You can get the cluster ID with the [list of clusters in the folder](cluster-list.md#list-clusters).

    1. Check the [server response](../api-ref/Cluster/updateHosts.md#yandex.cloud.operation.Operation) to make sure your request was successful.

- gRPC API {#grpc-api}

    1. [Get an IAM token for API authentication](../api-ref/authentication.md) and put it into an environment variable:

        ```bash
        export IAM_TOKEN="<IAM_token>"
        ```

    1. Clone the [cloudapi](https://github.com/yandex-cloud/cloudapi) repository:
       
       ```bash
       cd ~/ && git clone --depth=1 https://github.com/yandex-cloud/cloudapi
       ```
       
       Below, we assume that the repository contents reside in the `~/cloudapi/` directory.

    1. Call the [ClusterService/UpdateHosts](../api-ref/grpc/Cluster/updateHosts.md) method, e.g., via the following [gRPCurl](https://github.com/fullstorydev/grpcurl) request:

        {% note 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.
        
        {% cut "Format for listing settings" %}
        
        ```yaml
        "update_mask": {
            "paths": [
                "<setting_1>",
                "<setting_2>",
                ...
                "<setting_N>"
            ]
        }
        ```
        
        {% endcut %}
        
        {% endnote %}

        
        ```bash
        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` are the host settings:

        * `update_mask`: Comma-separated list of settings you want to update.
        * `host_name`: Target host name. You can get it with the [list of hosts in the cluster](#list-hosts).

        
        * `assign_public_ip`: Internet access to the host via a public IP address, `true` or `false`.


        * `hidden`: Determines whether the host is hidden, `true` or `false`. A hidden host is still accessible for read operations, but only through direct connections. This can be useful, for example, for making backups without adding extra load to the cluster.
        * `secondary_delay_secs`: Replica's lag behind the master in seconds. This setting can be useful for data recovery after operational errors.
        * `priority`: [Host priority for master promotion](../concepts/replication.md#master-failover).

        You can get the cluster ID with the [list of clusters in the folder](cluster-list.md#list-clusters).

    1. Check the [server response](../api-ref/grpc/Cluster/updateHosts.md#yandex.cloud.operation.Operation) to make sure your request was successful.

{% endlist %}

## Deleting a host {#remove-host}

You can remove a `MONGOD` host from a Yandex StoreDoc cluster unless it is the cluster’s sole host. To replace the only host, first create a new host and then delete the old one.

If the host being removed is the primary replica, Yandex StoreDoc will automatically elect a new primary replica.

In a [sharded Yandex StoreDoc cluster](shards.md#enable), you can remove the `MONGOS`, `MONGOCFG`, or `MONGOINFRA` hosts, provided you keep the [minimum number](#hosts-table) required for sharding.

{% list tabs group=instructions %}

- Management console {#console}

  To remove a host from a Yandex StoreDoc cluster:
  1. Open the [folder dashboard](https://console.yandex.cloud).
  1. Navigate to **Yandex StoreDoc**.
  1. Locate the Yandex StoreDoc cluster you need in the list, click its name, and select the **Hosts** tab.
  1. Find the host you need in the list, click ![image](../../_assets/console-icons/ellipsis.svg) in its row, and select **Delete**.
  1. In the window that opens, check **Delete host** and click **Confirm**.

- CLI {#cli}

  If you do not have the Yandex Cloud CLI yet, [install and initialize it](../../cli/quickstart.md#install).

  The folder used by default is the one specified when [creating](../../cli/operations/profile/profile-create.md) 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 delete a host from a Yandex StoreDoc cluster, run this command:

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

  You can get the host name from the list of [Yandex StoreDoc cluster hosts](#list-hosts) and the cluster name from the list [list of clusters in your folder](cluster-list.md#list-clusters).

- Terraform {#tf}

  To remove a host from a Yandex StoreDoc cluster:
  1. Open the current Terraform configuration file with the infrastructure plan.

     To learn how to create this file, see [Creating a cluster](cluster-create.md).
  1. Delete the relevant `host` section from the Yandex StoreDoc cluster description.
  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.
     1. Run this command:
     
        ```bash
        terraform validate
        ```
     
        Terraform will show any errors found in your configuration files.

  1. Type `yes` and press **Enter**.

     1. Run this command to view the planned changes:
     
        ```bash
        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.
     
     1. If everything looks correct, apply the changes:
        1. Run this command:
     
           ```bash
           terraform apply
           ```
     
        1. Confirm updating the resources.
        1. Wait for the operation to complete.

  For more information, see [this Terraform provider guide](../../terraform/resources/mdb_mongodb_cluster.md).

  {% note warning "Timeouts" %}
  
  The Terraform provider sets the following timeouts for Yandex StoreDoc 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.
  
  {% cut "How do I change these limits?" %}
  
  Add the `timeouts` block to the cluster description, for example:
  
  ```hcl
  resource "yandex_mdb_mongodb_cluster" "<cluster_name>" {
    ...
    timeouts {
      create = "1h30m" # An hour and a half
      update = "2h"    # Two hours
    }
  }
  ```
  
  {% endcut %}
  
  {% endnote %}

- REST API {#api}

  1. [Get an IAM token for API authentication](../api-ref/authentication.md) and put it into an environment variable:

      ```bash
      export IAM_TOKEN="<IAM_token>"
      ```

  1. Call the [Cluster.DeleteHosts](../api-ref/Cluster/deleteHosts.md) method, e.g., via the following [cURL](https://curl.se/) request:

      ```bash
      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 containing the host names you want to delete. You can get the host name from the [list of hosts in your cluster](#list-hosts).

      You can get the cluster ID with the [list of clusters in the folder](cluster-list.md#list-clusters).

  1. Check the [server response](../api-ref/Cluster/deleteHosts.md#yandex.cloud.operation.Operation) to make sure your request was successful.

- gRPC API {#grpc-api}

  1. [Get an IAM token for API authentication](../api-ref/authentication.md) and put it into an environment variable:

      ```bash
      export IAM_TOKEN="<IAM_token>"
      ```

  1. Clone the [cloudapi](https://github.com/yandex-cloud/cloudapi) repository:
     
     ```bash
     cd ~/ && git clone --depth=1 https://github.com/yandex-cloud/cloudapi
     ```
     
     Below, we assume that the repository contents reside in the `~/cloudapi/` directory.
  1. Call the [ClusterService.DeleteHosts](../api-ref/grpc/Cluster/deleteHosts.md) method, e.g., via the following [gRPCurl](https://github.com/fullstorydev/grpcurl) request:

      ```bash
      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 containing the host names you want to delete. You can get the host name from the [list of hosts in your cluster](#list-hosts).

      You can get the cluster ID with the [list of clusters in the folder](cluster-list.md#list-clusters).

  1. Check the [server response](../api-ref/grpc/Cluster/deleteHosts.md#yandex.cloud.operation.Operation) to make sure your request was successful.

{% endlist %}

## Starting host resync {#resetup}

To resync a host with other replicas in the Yandex StoreDoc cluster or shard, run a forced resync. This operation can be applied to a single `MONGOD` host at a time and is restricted to Yandex StoreDoc clusters containing more than two replicas. The restriction applies irrespective of host class and type. Resync also frees up the host’s storage by removing collections and documents marked as deleted.

During this operation:
1. The host stops accepting write requests. If the host was a `PRIMARY` replica, Yandex StoreDoc will attempt to demote it to a `SECONDARY` replica. In the event of failure, the operation is aborted.
1. The Yandex StoreDoc instance on the host is stopped, and all its data is deleted.
1. The Yandex StoreDoc instance restarts and re-downloads data from the replicas.
1. Once the host has synced with the other replicas in the Yandex StoreDoc cluster, it is demoted to a secondary replica.

   {% note info %}

   * During synchronization, the host cannot process requests properly, as it holds only a subset of the Yandex StoreDoc cluster’s data.
   * Estimated sync speed is 300 GB per day or more.

   {% endnote %}

{% list tabs group=instructions %}

- Management console {#console}

  To force a host resync:
  1. Open the [folder dashboard](https://console.yandex.cloud).
  1. Navigate to **Yandex StoreDoc**.
  1. Locate the Yandex StoreDoc cluster you need in the list, click its name, and select the **Hosts** tab.
  1. Find the host you need in the list, click ![image](../../_assets/console-icons/ellipsis.svg) in its row, and select **Resynchronize**.

- CLI {#cli}

  If you do not have the Yandex Cloud CLI yet, [install and initialize it](../../cli/quickstart.md#install).

  The folder used by default is the one specified when [creating](../../cli/operations/profile/profile-create.md) 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 force a host resync, run this command:

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

  You can get the host name from the [list of hosts in your folder](hosts.md#list-hosts). You can get the Yandex StoreDoc cluster name with the [list of clusters in the folder](cluster-list.md#list-clusters).

- REST API {#api}

  1. [Get an IAM token for API authentication](../api-ref/authentication.md) and put it into an environment variable:

      ```bash
      export IAM_TOKEN="<IAM_token>"
      ```

  1. Call the [Cluster.ResetupHosts](../api-ref/Cluster/resetupHosts.md) method, e.g., via the following [cURL](https://curl.se/) request:

      ```bash
      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 you want to re-sync. You can get the host name from the [list of hosts in your cluster](#list-hosts).

      You can get the cluster ID with the [list of clusters in the folder](cluster-list.md#list-clusters).

  1. Check the [server response](../api-ref/Cluster/resetupHosts.md#yandex.cloud.operation.Operation) to make sure your request was successful.

- gRPC API {#grpc-api}

  1. [Get an IAM token for API authentication](../api-ref/authentication.md) and put it into an environment variable:

      ```bash
      export IAM_TOKEN="<IAM_token>"
      ```

  1. Clone the [cloudapi](https://github.com/yandex-cloud/cloudapi) repository:
     
     ```bash
     cd ~/ && git clone --depth=1 https://github.com/yandex-cloud/cloudapi
     ```
     
     Below, we assume that the repository contents reside in the `~/cloudapi/` directory.
  1. Call the [ClusterService.ResetupHosts](../api-ref/grpc/Cluster/resetupHosts.md) method, e.g., via the following [gRPCurl](https://github.com/fullstorydev/grpcurl) request:

      ```bash
      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 you want to re-sync. You can get the host name from the [list of hosts in your cluster](#list-hosts).

      You can get the cluster ID with the [list of clusters in the folder](cluster-list.md#list-clusters).

  1. Check the [server response](../api-ref/grpc/Cluster/resetupHosts.md#yandex.cloud.operation.Operation) to make sure your request was successful.

{% endlist %}

## Restarting a host {#restart}

You can manually restart Yandex StoreDoc cluster hosts.

A host restart may result in temporary downtime for the Yandex StoreDoc cluster or [shard](../concepts/sharding.md):
* If your cluster consists of a single host.
* If the host being rebooted is the [primary replica](../concepts/replication.md).

A primary replica restart does not trigger an automatic failover. To prevent Yandex StoreDoc cluster downtime, [switch its primary replica](stepdown.md) before restarting the host.

{% note info %}

You can only restart one host at a time.

{% endnote %}

{% list tabs group=instructions %}

- Management console {#console}

  To restart a host:
  1. Open the [folder dashboard](https://console.yandex.cloud).
  1. Navigate to **Yandex StoreDoc**.
  1. Locate the Yandex StoreDoc cluster you need in the list, click its name, and select the **Hosts** tab.
  1. Find the host you need in the list, click ![image](../../_assets/console-icons/ellipsis.svg) in its row, and select **Restart**.
  1. Confirm host reboot.

- CLI {#cli}

  If you do not have the Yandex Cloud CLI yet, [install and initialize it](../../cli/quickstart.md#install).

  The folder used by default is the one specified when [creating](../../cli/operations/profile/profile-create.md) 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 restart a host, run this command:

  ```bash
  yc managed-mongodb hosts restart <host_name> \
    --cluster-name <cluster_name>
  ```

- REST API {#api}

  1. [Get an IAM token for API authentication](../api-ref/authentication.md) and put it into an environment variable:

      ```bash
      export IAM_TOKEN="<IAM_token>"
      ```

  1. Call the [Cluster.RestartHosts](../api-ref/Cluster/restartHosts.md) method, e.g., via the following [cURL](https://curl.se/) request:

      ```bash
      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 you want to restart. You can get the host name from the [list of hosts in your cluster](#list-hosts).

      You can get the cluster ID with the [list of clusters in the folder](cluster-list.md#list-clusters).

  1. Check the [server response](../api-ref/Cluster/restartHosts.md#yandex.cloud.operation.Operation) to make sure your request was successful.

- gRPC API {#grpc-api}

  1. [Get an IAM token for API authentication](../api-ref/authentication.md) and put it into an environment variable:

      ```bash
      export IAM_TOKEN="<IAM_token>"
      ```

  1. Clone the [cloudapi](https://github.com/yandex-cloud/cloudapi) repository:
     
     ```bash
     cd ~/ && git clone --depth=1 https://github.com/yandex-cloud/cloudapi
     ```
     
     Below, we assume that the repository contents reside in the `~/cloudapi/` directory.
  1. Call the [ClusterService.RestartHosts](../api-ref/grpc/Cluster/restartHosts.md) method, e.g., via the following [gRPCurl](https://github.com/fullstorydev/grpcurl) request:

      ```bash
      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 you want to restart. You can get the host name from the [list of hosts in your cluster](#list-hosts).

      You can get the cluster ID with the [list of clusters in the folder](cluster-list.md#list-clusters).

  1. Check the [server response](../api-ref/grpc/Cluster/restartHosts.md#yandex.cloud.operation.Operation) to make sure your request was successful.

{% endlist %}