Skip to content

Instantly share code, notes, and snippets.

@garryyao
Created February 10, 2023 18:10
Show Gist options
  • Save garryyao/627601497854327b4baf84145b1e8050 to your computer and use it in GitHub Desktop.
Save garryyao/627601497854327b4baf84145b1e8050 to your computer and use it in GitHub Desktop.
Atlas Cluster Automation Scripts
exports = async function() {
// Supply projectID and clusterNames...
const projectID = '<your Atlas project id>';
const clusterNames = ['<your cluster names>'];
// Get stored credentials...
console.log(context.values.get("AtlasPrivateKey"))
const username = context.values.get("AtlasPublicKey");
const password = context.values.get("AtlasPrivateKey");
// Set desired state...
const body = {paused: true};
var result = "";
clusterNames.forEach(async function (name) {
result = await context.functions.execute('modifyCluster', username, password, projectID, name, body);
console.log("Cluster " + name + ": " + EJSON.stringify(result));
if (result.error) {
return result;
}
})
return clusterNames.length + " clusters paused";
};
exports = async function() {
// Supply projectID and clusterNames...
const projectID = '<your Atlas project id>';
const clusterNames = ['<your cluster names>'];
// Get stored credentials...
const username = context.values.get("AtlasPublicKey");
const password = context.values.get("AtlasPrivateKey");
// Set desired state...
const body = {paused: false};
var result = "";
clusterNames.forEach(async function (name) {
result = await context.functions.execute('modifyCluster', username, password, projectID, name, body)
console.log("Cluster " + name + ": " + EJSON.stringify(result));
if (result.error) {
return result;
}
})
return clusterNames.length + " clusters resumed";
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment