# Scale a MongoDB Cluster Horizontally

DBaaS allows you to scale up and down the number of database replicas. Increased replica count may result in a cluster with improved availability, performance (capacity to handle more data reads), and fault tolerance for upgrades. A new IP address must be provided for each new instance. To do so, send a `PATCH` request with the new `instances` count (supported values are: 1, 3):

## Endpoint

Use the following endpoint to request the new instance count: `https://api.ionos.com/databases/mongodb/clusters/{clusterId}`

{% hint style="info" %}
**Note:** The sample cluster UUID is `d02de413-d5af-4104-a6f9-3a3c2766ee61`.
{% endhint %}

## Request

```bash
curl --include \
    --request PATCH \
    --user "clientname@ionos.com:Mb2.r5oHf-0t" \
    --header "Content-Type: application/json" \
    --data-binary '{
      "properties": {
        "instances": 3,
        "connections": [
          {
            "datacenterId": "b72ebcf5-6158-4ddb-8f65-31b20d82b6c7",
            "lanId": "2",
            "cidrList": [
              "10.7.222.3/24",
              "10.7.222.4/24",
              "10.7.222.5/24"
            ]
          }
       ]
      }
    }' 
```

## Response

```json
{
  "type": "cluster",
  "id": "d02de413-d5af-4104-a6f9-3a3c2766ee61",
  "metadata": {
    "state": "BUSY",
    "health": "HEALTHY",
    "createdDate": "2020-12-10T12:37:50.000Z",
    "createdBy": "clientname@ionos.com",
    "createdByUserId": "012342f-411f-1eeb-9d07-046c59cc737e"
  },
  "properties": {
    "type": "replicaset",
    "edition": "enterprise",
    "cores": 2,
    "ram": 2048,
    "storageSize": 10240,
    "storageType": "HDD",
    "displayName": "Represents database name",
    "location": "de/fra",
    "connections": [
      {
        "datacenterId": "b72ebcf5-6158-4ddb-8f65-31b20d82b6c7",
        "lanId": "2",
        "cidrList": [
          "10.1.1.3/24",
          "10.1.1.4/24",
          "10.1.1.5/24"
        ]
      }
    ],
    "instances": 3,
    "maintenanceWindow": {
      "time": "16:30:59",
      "dayOfTheWeek": "Monday"
    },
    "connectionString": "mongodb+srv://m-65f4a879f126e3c4.mongodb.de-fra.ionos.com"
  }
}
```

The patch example takes a previous cluster with one replica and adds two more replicas to it. The two new IP addresses are added to the connection properties `cidrList`, and the instances property receives the total number of replicas.

New servers are provisioned and added one at a time to the pool of replicas, implying an incremental rollout.

Downgrading a cluster follows the same pattern, with replica sets being removed one at a time and the desired replica set is reached.

{% hint style="info" %}
**Note:** Only **MongoDB Business** edition provides an option to downscale the number of instances. Scaling down may result in one or more failovers and the disruption of open connections.
{% endhint %}

For more information, see [<mark style="color:blue;">Replica Set Elections</mark>](https://www.mongodb.com/docs/manual/core/replica-set-elections/).


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.ionos.com/cloud/databases/mongodb/api/v1-api/modify-cluster-attributes/scale-a-mongodb-cluster-horizontally.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
