2 / 2
Aug 2024

Hi there :raised_hand: ,

I’m looking for a solution to change my cluster tier with Atlas API programmatically (I want to scale it down during nighttime and scale up during day time). Is there any way to do that?

I really appreciate any help you can provide.

Hi there!

Since there wasn’t a reply to your message, I tried to run it by our documentation bot. Here is the response I got :slight_smile:


Yes, you can programmatically change the cluster tier using the MongoDB Atlas API. This allows you to scale your cluster up or down based on your needs, such as scaling down during nighttime and scaling up during daytime.

To modify the cluster tier, you can use the Modify a Cluster endpoint of the Atlas API. Here is a general outline of how you can achieve this:

  1. Authenticate with the Atlas API: Ensure you have the necessary API keys and permissions to modify the cluster.
  2. Send a PATCH request to the Modify a Cluster endpoint: You will need to specify the new cluster tier in the request body.

Here is an example using curl:

curl -u "<publicKey>:<privateKey>" --digest \ -X PATCH "https://cloud.mongodb.com/api/atlas/v1.0/groups/<projectId>/clusters/<clusterName>" \ -H "Content-Type: application/json" \ -d '{ "providerSettings": { "instanceSizeName": "M10" // Change to your desired tier } }'

Replace <publicKey>, <privateKey>, <projectId>, and <clusterName> with your actual Atlas API credentials and cluster details. Adjust the instanceSizeName to the desired tier.

  1. Automate the process: You can use a cron job or a scheduled task in your preferred programming language to automate the scaling process based on the time of day.

Remember to handle any potential downtime or impact on your application when changing the cluster tier, as the cluster will reboot during the modification process.


Related Resources


Modify a Cluster
Docs

Configure Additional Settings
Docs

Create a Cluster
Docs