Atlas API Helper Library

A node.js library wrapping MongoDB Atlas API calls

This library contains helper functions to more easily make calls to Atlas via its REST api.

To use this library, add it as a dependeny to your node.js project:
"dependencies": { "atlasmanager": "github:mdg-2018/libAtlasManager" }
Then run:
npm install

AtlasApiClient

The AtlasApiClient class manages credentials for connecting to an Atlas project and has functions to manipulate Atlas clusters. Each AtlasApiClient handles a single Atlas project, so you'll need multiple AtlasApiClients if you want to make changes to clusters in many different projects

const AtlasApiClient = require('atlasmanager').AtlasApiClient;
var atlasApiClient = new AtlasApiClient("ProjectId","ApiKey","PublicApiKey","AtlasRoot" [optional])

Constructor Arguments

  • ProjectId: the ID of the Atlas project you want to target
  • ApiKey: An Atlas API key
  • PublicApiKey: Your Atlas public api key (usually a string with 8 characters)
  • AtlasRoot: Optional URL for the Atlas API starting point. Defaults to https://cloud.mongodb.com/api/atlas/v1.0/

API client functions

clusterinfo(clustername, callback)

Gets information about clusters in a project. In the future you will be able to pass in a clustername and get information about only a specific cluster, but I haven't gotten around to implementing it yet. For now just use it like this:

clusterinfo(null, function(clusters){ //do something });

getclusternames(callback)

Returns an array containing the name of each cluster in a project



createcluster(clusterdefinition, callback)

Creates a new cluster. clusterdefinition should be a json object describing the new state of the cluster. See the Atlas API docs for details. If no cluster definition is supplied, a cluster will be created based on default settings in the config.js file and given a random name.

No cluster definition: createcluster(null,null,function(result){ // do something })

With json string defintion: createcluster("{ // cluster defintion, see Atlas api docs }",null,function(result){ // do something })

With cluster definition file: createcluster(null,"/home/you/Documents/mycluster.json",function(result){ // do something })


deletecluster(clustername, deleteall, callback)

Terminates either a single cluster or all clusters in a project. To delete a single cluster:
deletecluster(myClusterName,false,function(result){ // do something })
To delete all clusters in a project: deletecluster(null, true, function(result){ // do something })



modifycluster(clusterename, clusterdefinition, callback)

Changes configuration of a single cluster. clusterdefinition should be a json object describing the new state of the cluster. See the Atlas API docs for details.



pausecluster(clustername, callback)

Pauses a cluster



resumecluster(clustername, callback)

Resumes a cluster