> For the complete documentation index, see [llms.txt](https://docs.ionos.com/cloud/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.ionos.com/cloud/api-reference/databases/v2-2/clusters/ensure-cluster.md).

# Ensure Cluster

Ensures that the Cluster with the provided ID is created or modified. The full Cluster needs to be provided to ensure (either update or create) the Cluster. Non present data will only be filled with defaults or left empty, but not take previous values into consideration.

```json
{"openapi":"3.0.3","info":{"title":"IONOS CLOUD - DBaaS - MongoDB","version":"2.0.0"},"tags":[{"name":"Clusters","description":"A MongoDB cluster is the top-level logical unit that groups one or more MongoDB server instances into a single, highly available data store. It represents the complete deployment—including the primary node, standby replicas, and configuration—allowing the API to manage and monitor the cluster as a single unified resource.\nThis tag groups all operations for clusters.\n"}],"servers":[{"url":"https://mongodb.gb-bhx.ionos.com/v2","description":"United Kingdom, Worcester"},{"url":"https://mongodb.us-ewr.ionos.com/v2","description":"United States, Newark"},{"url":"https://mongodb.gb-lhr.ionos.com/v2","description":"United Kingdom, London"},{"url":"https://mongodb.fr-par.ionos.com/v2","description":"France, Paris"},{"url":"https://mongodb.es-vit.ionos.com/v2","description":"Spain, Logroño"},{"url":"https://mongodb.us-mci.ionos.com/v2","description":"United States, Lenexa"}],"security":[{"tokenAuth":[]}],"components":{"securitySchemes":{"tokenAuth":{"type":"http","scheme":"bearer","bearerFormat":"JWT","description":"The token can be generated using the \n[Authentication API](https://api.ionos.com/docs/authentication/v1/#tag/tokens/operation/tokensGenerate).\n"}},"schemas":{"ClusterEnsure":{"type":"object","required":["id","properties"],"properties":{"id":{"type":"string","description":"The ID (UUID) of the Cluster.","format":"uuid"},"metadata":{"description":"Metadata","additionalProperties":true},"properties":{"$ref":"#/components/schemas/Cluster"}}},"Cluster":{"type":"object","description":"A MongoDB cluster is the top-level logical unit that groups one or more MongoDB server instances into a single, highly available data store. It represents the complete deployment—including the primary node, standby replicas, and configuration—allowing the API to manage and monitor the cluster as a single unified resource.\n","oneOf":[{"$ref":"#/components/schemas/EnterpriseCluster"},{"$ref":"#/components/schemas/BusinessCluster"}],"discriminator":{"propertyName":"edition","mapping":{"BUSINESS":"#/components/schemas/BusinessCluster","ENTERPRISE":"#/components/schemas/EnterpriseCluster"}}},"EnterpriseCluster":{"type":"object","required":["name","connection","maintenanceWindow","edition","instances","version","snapshot"],"properties":{"name":{"$ref":"#/components/schemas/MongoClusterName"},"description":{"$ref":"#/components/schemas/MongoClusterDescription"},"version":{"$ref":"#/components/schemas/MongoClusterVersion"},"connection":{"$ref":"#/components/schemas/MongoClusterConnection"},"maintenanceWindow":{"$ref":"#/components/schemas/MaintenanceWindow"},"credentials":{"$ref":"#/components/schemas/MongoUser"},"restoreFromSnapshot":{"$ref":"#/components/schemas/MongoRestoreFromSnapshot"},"edition":{"allOf":[{"$ref":"#/components/schemas/MongoEdition"}],"enum":["ENTERPRISE"]},"sharding":{"$ref":"#/components/schemas/MongoSharding"},"instances":{"$ref":"#/components/schemas/InstanceConfiguration"},"logsEnabled":{"$ref":"#/components/schemas/LogsEnabled"},"metricsEnabled":{"$ref":"#/components/schemas/MetricsEnabled"},"snapshot":{"$ref":"#/components/schemas/ClusterSnapshot"}}},"MongoClusterName":{"type":"string","description":"The name of the MongoDB cluster.\nMust be 63 characters or less and must begin and end with an alphanumeric character (`[a-z0-9A-Z]`)\nwith dashes (`-`), underscores (`_`), dots (`.`), and alphanumerics between.\n","pattern":"^[A-Za-z0-9][-A-Za-z0-9_.]*[A-Za-z0-9]$","minLength":2,"maxLength":63},"MongoClusterDescription":{"type":"string","description":"Human-readable description for the cluster."},"MongoClusterVersion":{"type":"string","description":"The MongoDB version for the cluster. Use GET /versions to retrieve the\nlist of supported versions and their available upgrade paths.\n"},"MongoClusterConnection":{"description":"Connection information of the mongo cluster.\n","type":"object","required":["datacenterId","lanId","instanceAddresses"],"properties":{"datacenterId":{"description":"The datacenter to connect your instance to. Immutable. Cannot be changed after cluster creation.","type":"string","format":"uuid"},"lanId":{"description":"The numeric LAN ID to connect your instance to. Immutable. Cannot be changed after cluster creation.","type":"string"},"instanceAddresses":{"type":"array","description":"A list of IP addresses assigned to the cluster instances. The number of IP addresses must match the number of instances in the cluster.\n","items":{"$ref":"#/components/schemas/MongoClusterInstanceIp"}}}},"MongoClusterInstanceIp":{"type":"string","description":"The IP and netmask for a cluster instance.\nNote the following unavailable IP range:\n10.208.0.0/12\n"},"MaintenanceWindow":{"description":"A weekly 4 hour-long window, during which maintenance might occur.\n","properties":{"time":{"type":"string","description":"Start of the maintenance window in UTC time."},"dayOfTheWeek":{"$ref":"#/components/schemas/DayOfTheWeek"}},"required":["time","dayOfTheWeek"],"type":"object"},"DayOfTheWeek":{"description":"The name of the week day.","type":"string","enum":["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]},"MongoUser":{"type":"object","description":"Credentials for the initial database user. Required when creating a cluster. On update, omitting\n`credentials` leaves the existing user unchanged; if `credentials` is supplied, `username`,\n`database` and `password` are all required.\nOnly `username` and `database` are returned in responses; `password` is write-only and never returned.\n","required":["username","database"],"properties":{"username":{"$ref":"#/components/schemas/MongoUsername"},"password":{"$ref":"#/components/schemas/MongoUserPassword"},"database":{"$ref":"#/components/schemas/MongoDatabaseName"}}},"MongoUsername":{"type":"string","description":"The username of the initial MongoDB user.\nMust be between 2 and 16 characters and must include only alphanumeric characters (`[A-Za-z0-9]`)\nand underscores (`_`). Some usernames are reserved for platform use.\n","pattern":"^[A-Za-z0-9_]+$","minLength":2,"maxLength":16},"MongoUserPassword":{"type":"string","description":"The password for the initial MongoDB user.\nPassword is required whenever credentials are supplied, on create and on update; never returned in responses.\nMust be between 8 and 256 characters long.\nFor a strong password we recommend that it also meets the following\ncriteria, though these are not enforced:\n- Contains at least one lowercase letter.\n- Contains at least one uppercase letter.\n- Contains at least one digit (0-9).\n- Contains at least one special character from the set: @$!%*?&\n","writeOnly":true,"minLength":8,"maxLength":256},"MongoDatabaseName":{"type":"string","description":"The name of the initial database to be created.\nMust be 63 characters or less and must include only alphanumeric characters (`[A-Za-z0-9]`)\nand underscores (`_`).\n","pattern":"^[A-Za-z0-9_]+$","minLength":2,"maxLength":63},"MongoRestoreFromSnapshot":{"type":"object","additionalProperties":false,"minProperties":1,"writeOnly":true,"description":"Restores the cluster from a snapshot.\nOn cluster creation, set `sourceSnapshotId` (optionally `recoveryTargetDatetime`) to initialize the new cluster from an existing snapshot. Only snapshots from clusters within the same region are eligible.\nOn in-place modification, set `recoveryTargetDatetime` only; the restore source is inferred from the cluster's own snapshots. The current data is overwritten with the restored data, and the cluster may experience a brief period of downtime during this process.\nMongoDB supports point-in-time recovery: `recoveryTargetDatetime` restores the cluster to any moment within the snapshot's recovery window by restoring the base snapshot and replaying the oplog up to that time.\n","properties":{"sourceSnapshotId":{"type":"string","format":"uuid","description":"UUID of the snapshot to restore from. Required for restore on cluster creation; not valid for in-place restore, where the source is inferred from the cluster's own snapshots.\n"},"recoveryTargetDatetime":{"type":"string","format":"date-time","description":"An ISO 8601 timestamp for point-in-time recovery; the cluster is restored to this exact moment (within the available recovery window), not merely to the nearest snapshot.\nOptional on cluster creation — if omitted, the source snapshot (`sourceSnapshotId`) is applied in full; required for in-place restore.\n"}}},"MongoEdition":{"type":"string","enum":["ENTERPRISE","BUSINESS"],"description":"The edition of the MongoDB cluster. This field indicates the licensing and feature set of the running database instance."},"MongoSharding":{"type":"object","description":"Sharding properties for the cluster.","properties":{"enabled":{"type":"boolean","description":"A flag to activate or deactivate sharding for this cluster. Can only be set to true if the MongoDB edition is ENTERPRISE.","default":false},"shards":{"type":"integer","minimum":2,"maximum":5,"description":"Number of shards. If sharding is enabled, this field specifies the number of shards to create in the cluster.\nThe number of shards must be between 2 and 5.\nWhen sharding is enabled, the instances count signifies the number of replicas per shard.\n","default":2}}},"InstanceConfiguration":{"type":"object","required":["count","ram","cores","storageSize"],"properties":{"count":{"$ref":"#/components/schemas/InstancesCount"},"ram":{"$ref":"#/components/schemas/InstancesMemory"},"cores":{"$ref":"#/components/schemas/InstancesCores"},"storageSize":{"$ref":"#/components/schemas/InstancesStorageSize"}}},"InstancesCount":{"description":"The total number of instances in the cluster (one primary and n-1\nsecondary).\n","type":"integer","minimum":1,"maximum":9},"InstancesMemory":{"type":"integer","description":"The amount of memory per instance in gigabytes (GB).","minimum":6,"maximum":240},"InstancesCores":{"type":"integer","description":"The number of CPU cores per instance.","minimum":1,"maximum":62},"InstancesStorageSize":{"type":"integer","description":"The amount of storage per instance in gigabytes (GB).","minimum":10,"maximum":4096},"LogsEnabled":{"type":"boolean","default":false,"description":"Allows or disallows the collection and reporting of logs for this cluster's observability.\nIf the observability service is not activated on the contract, this setting is accepted but has no effect;\nlog collection will not be enabled until the observability service is activated.\n"},"MetricsEnabled":{"type":"boolean","default":false,"description":"Allows or disallows the collection and reporting of metrics for this cluster's observability.\nIf the observability service is not activated on the contract, this setting is accepted but has no effect;\nmetric collection will not be enabled until the observability service is activated.\n"},"ClusterSnapshot":{"type":"object","description":"Snapshot storage and retention configuration for the cluster.","properties":{"location":{"$ref":"#/components/schemas/SnapshotLocationName"},"retentionDays":{"$ref":"#/components/schemas/SnapshotRetentionDays"}},"required":["location","retentionDays"]},"SnapshotLocationName":{"description":"The Object Storage location where the snapshots will be created.\nFor added data safety, use a different location than the cluster.\n","type":"string"},"SnapshotRetentionDays":{"description":"Configures how many days cluster snapshots are retained before being automatically deleted.\nAccepted values: 3, 4, 5, 6, 7, 15, 30, 60, 90, 120, 180, 360.\nReducing this value purges existing snapshots that fall outside the new retention window.\n","type":"integer","enum":[3,4,5,6,7,15,30,60,90,120,180,360]},"BusinessCluster":{"type":"object","required":["name","connection","maintenanceWindow","edition","snapshot","instanceTemplateId","instanceCount","version"],"properties":{"name":{"$ref":"#/components/schemas/MongoClusterName"},"description":{"$ref":"#/components/schemas/MongoClusterDescription"},"version":{"$ref":"#/components/schemas/MongoClusterVersion"},"connection":{"$ref":"#/components/schemas/MongoClusterConnection"},"maintenanceWindow":{"$ref":"#/components/schemas/MaintenanceWindow"},"credentials":{"$ref":"#/components/schemas/MongoUser"},"restoreFromSnapshot":{"$ref":"#/components/schemas/MongoRestoreFromSnapshot"},"edition":{"allOf":[{"$ref":"#/components/schemas/MongoEdition"}],"enum":["BUSINESS"]},"instanceTemplateId":{"type":"string","description":"A unique identifier for the instance template. Check /instance-templates for a list.","format":"uuid"},"instanceCount":{"$ref":"#/components/schemas/InstancesCount"},"logsEnabled":{"$ref":"#/components/schemas/LogsEnabled"},"metricsEnabled":{"$ref":"#/components/schemas/MetricsEnabled"},"snapshot":{"$ref":"#/components/schemas/ClusterSnapshot"}}},"ClusterRead":{"type":"object","required":["id","type","href","metadata","properties"],"properties":{"id":{"type":"string","description":"The ID (UUID) of the Cluster.","format":"uuid"},"type":{"description":"The type of the resource.","type":"string","enum":["cluster"]},"href":{"description":"The URL of the Cluster.","type":"string"},"metadata":{"$ref":"#/components/schemas/ClusterMetadata"},"properties":{"$ref":"#/components/schemas/Cluster"}}},"ClusterMetadata":{"readOnly":true,"allOf":[{"$ref":"#/components/schemas/Metadata"},{"type":"object","properties":{"state":{"$ref":"#/components/schemas/MongoClusterStates"},"statusMessage":{"type":"string","description":"A human-readable message describing the current state. Populated when `state` is `FAILED`.","readOnly":true}}},{"type":"object","properties":{"connectionUri":{"type":"string","description":"The connection string used to access the cluster.","readOnly":true}}}]},"Metadata":{"type":"object","description":"Metadata of the resource.","properties":{"createdDate":{"type":"string","format":"date-time","description":"The ISO 8601 creation timestamp.","readOnly":true},"createdBy":{"type":"string","description":"Unique name of the identity that created the resource.","readOnly":true},"createdByUserId":{"type":"string","description":"Unique id of the identity that created the resource.","readOnly":true},"lastModifiedDate":{"type":"string","format":"date-time","description":"The ISO 8601 modified timestamp.","readOnly":true},"lastModifiedBy":{"type":"string","description":"Unique name of the identity that last modified the resource.","readOnly":true},"lastModifiedByUserId":{"type":"string","description":"Unique id of the identity that last modified the resource.","readOnly":true},"resourceURN":{"type":"string","description":"Unique name of the resource.","readOnly":true}}},"MongoClusterStates":{"description":"The current lifecycle state of the cluster.\n- `PROVISIONING`: The system is actively applying the changes.\n- `AVAILABLE`: The resource is fully operational with no pending changes.\n- `UPDATING`: A modification is in progress.\n- `DESTROYING`: The resource is being deleted.\n- `FAILED`: The provisioning failed due to an internal error.\n","type":"string","enum":["PROVISIONING","AVAILABLE","UPDATING","DESTROYING","FAILED"],"readOnly":true},"Error":{"description":"The Error object is used to represent an error response from the API.\n","type":"object","properties":{"httpStatus":{"type":"integer","description":"The HTTP status code of the operation."},"messages":{"type":"array","description":"A list of error messages.\n","items":{"type":"object","properties":{"errorCode":{"type":"string","description":"Application internal error code\n"},"message":{"type":"string","description":"A human readable explanation specific to this occurrence of the\nproblem.\n"}}}}}}},"responses":{"BadRequest":{"description":"### Bad Request\nThe request send to the API was malformed.\n","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"Unauthorized":{"description":"### Unauthorized\nThe request is missing authorization information or the authorization information provided are expired.\n","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"NotAllowed":{"description":"### Not Allowed\nThe user issuing the request does not have the needed permissions.\n","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"NotFound":{"description":"### Not Found\nThe resource that was requested could not be found.\n","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"Conflict":{"description":"### Conflict\nThe UUID is already taken by another party, follow the guides to generate UUIDs uniquely.\n","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"UnsupportedMediaType":{"description":"### Unsupported Media Type\nThe request has an unsupported media type.\n","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"UnprocessableEntity":{"description":"### Unprocessable Entity\nThe request was well-formed but was unable to be followed due to semantic errors.\n","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"TooManyRequests":{"description":"### Too Many Requests\nThe user has sent too many requests in a given amount of time.\n","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"InternalError":{"description":"### Internal Server Error\nAn internal error occurred. We apologize for the inconvenience!\n","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"ServiceUnavailable":{"description":"### Service Unavailable\nThe server is currently unable to handle the request due to a temporary overloading or maintenance of the server.\n","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"UnexpectedError":{"description":"### Unexpected Internal Server Error\nAn unexpected internal error occurred. We apologize for the inconvenience!\n","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}},"paths":{"/clusters/{clusterId}":{"put":{"operationId":"clustersPut","summary":"Ensure Cluster","tags":["Clusters"],"description":"Ensures that the Cluster with the provided ID is created or modified.\nThe full Cluster needs to be provided to ensure\n(either update or create) the Cluster. Non present data will\nonly be filled with defaults or left empty, but not take\nprevious values into consideration.\n","parameters":[{"name":"clusterId","in":"path","schema":{"type":"string","format":"uuid"},"required":true,"description":"The ID (UUID) of the Cluster."}],"requestBody":{"description":"update Cluster","required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ClusterEnsure"}}}},"responses":{"200":{"description":"Cluster successfully updated.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ClusterRead"}}}},"201":{"description":"Cluster successfully ensured.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ClusterRead"}}}},"400":{"$ref":"#/components/responses/BadRequest"},"401":{"$ref":"#/components/responses/Unauthorized"},"403":{"$ref":"#/components/responses/NotAllowed"},"404":{"$ref":"#/components/responses/NotFound"},"409":{"$ref":"#/components/responses/Conflict"},"415":{"$ref":"#/components/responses/UnsupportedMediaType"},"422":{"$ref":"#/components/responses/UnprocessableEntity"},"429":{"$ref":"#/components/responses/TooManyRequests"},"500":{"$ref":"#/components/responses/InternalError"},"503":{"$ref":"#/components/responses/ServiceUnavailable"},"default":{"$ref":"#/components/responses/UnexpectedError"}}}}}}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.ionos.com/cloud/api-reference/databases/v2-2/clusters/ensure-cluster.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
