# Create a Sharded Database Cluster

This section shows you how to create a MongoDB sharded cluster using the <code class="expression">space.vars.ionos\_cloud</code> API. This feature is available only for enterprise clusters.

For information about prerequisites to retrieve the data center UUID, query database status, connect to the cluster, and prepare the network, see [<mark style="color:blue;">Create a Cluster</mark>](/cloud/databases/mongodb/api/v1-api/create-mongodb-cluster.md).

## Create a cluster

This request creates a MongoDB version 6.0 sharded database cluster of two shards with three replicas each. The size of each node is specified in the request.

{% hint style="info" %}
**Note:** The use of `shards` in the request identifies the number of shards, while `type` defines the cluster as a sharded cluster.
{% endhint %}

{% hint style="info" %}
**Note:** Only contract administrators and owners can create and change database clusters. In contrast, the running database cluster can be accessed from all servers in the specified LAN.
{% endhint %}

## Resource consumption

In total, six database nodes are created, and consequently, the number of billed resources is 24 cores, 12 GB memory, and 120 GB storage.

{% hint style="info" %}
**Note:** In addition, a set of three config servers is created with two cores, 4 GB memory, and 40 GB storage each. These are *excluded* from the billed resources.
{% endhint %}

### Endpoint

Use the following endpoint to create a sharded cluster: `https://api.ionos.com/databases/mongodb/clusters`

{% hint style="info" %}
**Note:** The sample data center UUID is `b1432c51-c20a-4f83-876f-c3a8a9e1fbec`.
{% endhint %}

### Request

```bash
curl --include \
    --request POST \
    --user "clientname@ionos.com:Mb2.r5oHf-0t" \
    --header "Content-Type: application/json" \
    --data-binary '{
      "metadata": {},
      "properties":
        {
        "mongoDBVersion": "6.0",
        "instances": 3,
        "location": "de/fra",
        "displayName": "a good name for a database",
        "connections": [
          {
            "datacenterId": "b1432c51-c20a-4f83-876f-c3a8a9e1fbec",
            "lanId": "28",
            "cidrList": ["10.1.1.3/24", "10.1.1.4/24", "10.1.1.5/24"]
          }
        ],
        "type": "sharded-cluster",
        "shards": 2,
        "edition": "enterprise",
        "cores": 4,
        "ram": 2048,
        "storageSize": 20000,
        "storageType": "HDD"
      }
    }' \
```

### Response

```json
{
  "type": "cluster",
  "id": "498ae72f-411f-11eb-9d07-046c59cc737e",
  "metadata": {
    "state": "BUSY",
    "health": "UNKNOWN",
    "createdDate": "2020-12-10T12:37:50.000Z",
    "createdBy": "clientname@ionos.com",
    "createdByUserId": "012342f-411f-1eeb-9d07-046c59cc737e"
  },
  "properties": {
    "displayName": "a good name for a database",
    "location": "de/fra",
    "connections": [
      {
        "datacenterId": "b1432c51-c20a-4f83-876f-c3a8a9e1fbec",
        "lanId": "28",
        "cidrList": [
          "10.1.1.3/24",
          "10.1.1.4/24",
          "10.1.1.5/24"
        ]
      }
    ],
    "instances": 3,
    "shards": 2,
    "edition": "enterprise",
    "cores": 4,
    "ram": 2048,
    "storageSize": 20000,
    "storageType": "HDD",
    "type": "sharded-cluster",
    "maintenanceWindow": {
      "time": "15:39:01",
      "dayOfTheWeek": "Friday"
    },
    "connectionString": "mongodb+srv://m-65f4a879f126e3c4.mongodb.de-fra.ionos.com"
  }
}
```

At this point, you have created your first MongoDB sharded cluster. The deployment of the database takes several minutes. For more information about determining if your cluster is ready, see [<mark style="color:blue;">Querying database status</mark>](/cloud/databases/mongodb/api/v1-api/create-mongodb-cluster.md#query-database-status).

When the cluster is ready, add the role `enableSharding` to a user in order to allow shard management capabilities. For managing user roles, see [<mark style="color:blue;">Update the roles</mark>](/cloud/databases/mongodb/api/v1-api/users-management.md#update-the-roles). Only users with `enableSharding` role can shard a collection. For more information, see [<mark style="color:blue;">shardCollection</mark>](https://www.mongodb.com/docs/manual/reference/method/sh.enableSharding/).


---

# 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/create-a-sharded-cluster.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.
