MongoDB v2 API Workflows
Use these end-to-end workflows to deploy, connect, operate, and restore resources using the IONOS CLOUD DBaaS MongoDB v2 API.
Deploy a MongoDB cluster: Plan your cluster configuration and provision it through to the
AVAILABLEstate.Connect to your MongoDB cluster: Connect to a provisioned cluster using its connection URI and credentials.
Operate a MongoDB cluster: Manage a running cluster with day-to-day operations and deprovision it when no longer needed.
Restore from a snapshot: Recover cluster data to a specific point in time using Point-in-Time Recovery (PITR).
Verify snapshot data residency: Confirm that cluster snapshots are stored in the expected Object Storage region.
Deploy a MongoDB Cluster
Use this workflow to plan and provision a new MongoDB cluster.
Prerequisites
An access token that authenticates your API requests. For more information, see Authentication.
The Universally Unique Identifier (UUID) of an existing Virtual Data Center (VDC) (
datacenterId) that resides in the same region as your target MongoDB endpoint. To create a VDC, use IONOS CLOUD API.The identifier of a private Local Area Network (LAN) (
lanId) within that VDC. The cluster connects to this LAN during provisioning. To create a LAN, use IONOS CLOUD API.Static IP addresses in Classless Inter-Domain Routing (CIDR) notation (
instanceAddresses): one for each instance of the cluster, or exactly three for anENTERPRISEcluster with sharding enabled. Example:192.168.2.101/24. The range10.208.0.0/12is unavailable.
Plan Configuration
Find the snapshot location: Specify the region where your cluster's snapshots are stored.
Action: Browse the list to identify an available snapshot region.
Result: The API returns HTTP
200with a list of snapshot locations. Note thelocationvalue to use inproperties.snapshot.locationwhen provisioning the cluster.
Select a MongoDB version: Retrieve the list of supported MongoDB versions.
Action: Identify the version that matches your requirements.
Result: The API returns HTTP
200with a list of supported MongoDB versions. Each entry includes the version identifier, its lifecyclestatus(BETA,SUPPORTED,RECOMMENDED, orDEPRECATED), acanUpgradeToarray listing available upgrade paths, and the lifecycle datescreationFreezeDateanddeprecationDate. Note the version identifier to use forproperties.versionwhen provisioning the cluster.
Choose an edition: Select the edition that matches your requirements.
BUSINESS: Retrieve the available instance templates with Retrieve all InstanceTemplates. Each template definescores,ram, andstorageSize. Note theidof the template to use asinstanceTemplateId.ENTERPRISE: Define the resources yourself in theinstancesobject (count,ram,cores, andstorageSize). Optionally activate sharding (sharding.enabledandsharding.shards, from 2 to 5) and the BI Connector (biConnectorEnabled).
Provision a Cluster
Create the cluster:
API: Create Cluster
Action: Provide the required fields:
edition,name,version,connection(containingdatacenterId,lanId, andinstanceAddresses),snapshot(containinglocationandretentionDays),maintenanceWindow, andcredentials(containingusername,password, anddatabase). ForBUSINESS, also provideinstanceTemplateIdandinstanceCount. ForENTERPRISE, also provideinstances.
Example request bodies for each edition:
{
"properties": {
"edition": "ENTERPRISE",
"name": "cms-prod",
"version": "7",
"instances": {
"count": 3,
"ram": 8,
"cores": 4,
"storageSize": 100
},
"connection": {
"datacenterId": "5a029f4a-72e5-11ec-90d6-0242ac120003",
"lanId": "2",
"instanceAddresses": [
"192.168.2.101/24",
"192.168.2.102/24",
"192.168.2.103/24"
]
},
"snapshot": {
"location": "eu-south-2",
"retentionDays": 7
},
"maintenanceWindow": {
"dayOfTheWeek": "Sunday",
"time": "02:00:00"
},
"credentials": {
"username": "my_db_user",
"password": "S3cure!Pass",
"database": "mydb"
}
}
}Result: The API returns HTTP 201. Note the id: you need it in every subsequent cluster operation. metadata.state starts as PROVISIONING.
Next steps: To connect to your cluster, see Connect to Your MongoDB Cluster.
Connect to Your MongoDB Cluster
Use this workflow to retrieve the MongoDB cluster connection URI and connect using your credentials.
Prerequisites
Ensure the cluster is in the
AVAILABLEstate.You must have the
id(UUID) of the cluster. You receive this when you complete the Deploy a MongoDB Cluster workflow.You must have the
credentials.username,credentials.password, andcredentials.databaseset during provisioning.Your client must have network access to the LAN that the cluster is connected to.
Retrieve the Connection Details
Retrieve the cluster:
API: Retrieve Cluster
Result: The API returns HTTP
200. Notemetadata.connectionUri. Example:mongodb+srv://m-12abd343.mongodb.gb-bhx.ionoscloud.com.
Operate a MongoDB Cluster
Use this workflow to manage a running cluster and deprovision it when it is no longer needed.
Prerequisites
Ensure the cluster is in the
AVAILABLEstate.You must have the
id(UUID) of the cluster.
Review Snapshots
Action: Filter by
filter.clusterIdto list the snapshots of one cluster.Result: Each snapshot shows
earliestRecoveryTargetTimeandlatestRecoveryTargetTime. IflatestRecoveryTargetTimeisnull, the cluster can be restored up to the current time.
Scale Cluster Resources
API: Update Cluster
Action: For
BUSINESS, changeinstanceTemplateIdorinstanceCount. ForENTERPRISE, change the values ininstances. Submit the full cluster object. If the number of instances changes, updateconnection.instanceAddressesin the same request so that it contains exactly one address per instance. For example, increasing a three-instance cluster to four instances requires a fourth address in the list. For anENTERPRISEcluster with sharding enabled, the list always contains exactly three addresses.Result: The API accepts the change and
metadata.statemoves toUPDATING. Poll until it returns toAVAILABLE.
Add Shards
API: Update Cluster
Action: On an
ENTERPRISEcluster with sharding enabled, increasesharding.shardsand submit the full cluster object.Result: The cluster moves to
UPDATINGand returns toAVAILABLEwhen the change completes.
Monitor Version Lifecycle
Action: Check the
status,creationFreezeDate, anddeprecationDateof your cluster's version. ADEPRECATEDstatus or an approachingdeprecationDateindicates that you should plan an upgrade.
Upgrade the MongoDB Version
API: Update Cluster
Action: Set
properties.versionto a version listed in thecanUpgradeToarray of your current version. Downgrades are not supported.
Update the Maintenance Window
API: Update Cluster
Action: Change
maintenanceWindow.dayOfTheWeekandmaintenanceWindow.time(UTC). The window is four hours long and starts attime.
Deprovision the Cluster
Deprovision the cluster when it is no longer needed to release resources.
API: Delete Cluster
Action: Submit the delete request to permanently remove the cluster.
Result: The API returns HTTP
202, confirming the delete request is accepted. Deletion is asynchronous:metadata.statemoves toDESTROYINGand the cluster is removed once deletion completes.
Restore from a Snapshot
Use this workflow to recover cluster data to a specific point in time. MongoDB supports Point-in-Time Recovery (PITR): the restore starts from the base snapshot and replays the oplog up to recoveryTargetDatetime.
Prerequisites
An access token that authenticates your API requests. For more information, see Authentication.
The
idof the source cluster.
Step 1: Find the Snapshot
List the snapshots:
Action: Filter by
filter.clusterId.Result: Note the snapshot
idand its recovery window (earliestRecoveryTargetTimetolatestRecoveryTargetTime). Also noterequiredStorageSize, the minimum storage needed to restore this snapshot, in MiB.
Path 1: Create a New Cluster from a Snapshot
API: Create Cluster
Action: Provide the full cluster configuration and add
restoreFromSnapshotwithsourceSnapshotId. Optionally addrecoveryTargetDatetime. If omitted, the snapshot is applied in full.Result: A new cluster is provisioned with the restored data.
Path 2: Restore the Existing Cluster in Place
Use this path when you must recover the current cluster to an earlier state. This path is destructive and cannot be undone.
API: Update Cluster
Action: Submit the full cluster object and add
restoreFromSnapshotwithrecoveryTargetDatetimeonly. Do not setsourceSnapshotId: the source is inferred from the cluster's own snapshots.Result: The cluster is restored to the target time.
Verify Snapshot Data Residency
Use this workflow to confirm that cluster snapshots are stored in the expected Object Storage region.
Find the Cluster's Snapshot Location
API: Retrieve Cluster
Result: Note
properties.snapshot.location.
Last updated
Was this helpful?