Automate the Automation on MongoDB Atlas
Rate this article
MongoDB Atlas is an awesome Cloud Data Platform providing an immense amount of automation to set up your databases, data lakes, charts, full-text search indexes, and more across all major cloud providers around the globe. Through the MongoDB Atlas GUI, you can easily deploy a fully scalable global cluster across several regions and even across different cloud providers in a matter of minutes. That's what I call automation. Using the MongoDB GUI is super intuitive and great, but how can I manage all these features in my own way?
The answer is simple and you probably already know it….APIs!
MongoDB Atlas has a full featured API which allows users to programmatically manage all Atlas has to offer.
The main idea is to enable users to integrate Atlas with all other aspects of your Software Development Life Cycle (SDLC), giving the ability for your DevOps team to create automation on their current processes across all their environments (Dev, Test/QA, UAT, Prod).
One example would be the DevOps teams leveraging APIs on the creation of ephemeral databases to run their CI/CD processes in lower environments for test purposes. Once it is done, you would just terminate the database deployment.
Another example we have seen DevOps teams using is to incorporate the creation of the databases needed into their Developers Portals. The idea is to give developers a self-service experience, where they can start a project by using a portal to provide all project characteristics (tech stack according to their coding language, app templates, etc.), and the portal will create all the automation to provide all aspects needed, such as a new code repo, CI/CD job template, Dev Application Servers, and a MongoDB database. So, they can start coding as soon as possible!
Even though the
is great with lots of examples using cURL, we thought developers would appreciate it if they could also have all these in one of their favorite tools to work with APIs. I am talking about
, an API platform for building and using APIs. So, we did it! Below you will find step-by-step instructions on how to use it.
- Create a freeto have access to a free cluster to play around in. Make sure you create an organization and a project. Don't skip that step. Here is a coupon code—GOATLAS10—for some credits to explore more features (valid as of August 2021). Watch thisto learn how to add these credits to your account.
- Create a(cluster) via the Atlas UI or the MongoDB CLI (check out thefor detailed instructions). Note that a free database deployment will allow you to run most of the API calls. Use an M10 database deployment or higher if you want to have full access to all of the APIs. Feel free to explore all of the other database deployment options, but the default options should be fine for this example.
- Navigate to your Project Settings and retrieve your Project ID so it can be used in one of our examples below.
- Click on the MongoDB Atlas Collection. Under the Authorization tab, choose the Digest Auth Type and use the public key as the user and the private key as your password.
- Open up the Get All Clusters API call under the cluster folder.
- Execute the API call by hitting the Send button and you should get a response containing a list of all your clusters (database deployments) alongside the cluster details, like whether backup is enabled or the cluster is running.
Now explore all the APIs available to create your own automation.
One last tip: Once you have tested all your API calls to build your automation, Postman allows you to export that in code snippets in your favorite programming language.
Hope you enjoyed it! Please share this with your team and community. It might be really helpful for everyone!
Here are some other great posts related to this subject:
*A subset of API endpoints are supported in (free) M0, M2, and M5 clusters.