MongoDB Atlas
Comprehensive guide for connecting to a MongoDB Cluster from your DevBox.
Architecture Diagram
This would be done by setting up the cluster in your Atlas dashboard through one of 3 available cloud providers (AWS, Azure, or GCP) and accessing it through DevBox.
Prerequisites
Before you begin, create your account with MongoDB.
MongoDB only supports Private Endpoint access for Dedicated or Serverless clusters. Private Endpoint access for the Shared cluster is not yet supported.
Existing MongoDB Cluster
Step 1: Creating a Private Endpoint
To connect to a database cluster, you must create a private endpoint with one of MongoDB's three supported cloud providers (AWS, GCP, Azure).
To check and configure the same, follow the below steps:
- Go to MongoDB Atlas.
- Go to Security > Network Access and open the Private Endpoint tab.
- Click on Add Private Endpoint and choose your cloud provider. For this tutorial, we will be using Azure.
You must provide the billing information in the Edit Payment Method form if you still need to get the payment method configured for your organization.
- Click on Next and choose the Region where you want to deploy your endpoint.
- Enter your Resource Group Name, Virtual Network Name, Subnet Name, and the name you want to give to your endpoint.
- Copy and run this PrivateLink Endpoint Command where your Azure CLI is configured. Remember that you can only copy the command once Atlas finishes creating VNET resources in the background for internal use.
- After creating the private endpoint, copy the Private Endpoint Resource ID and Private Endpoint IP Address and paste them into the MongoDB Private Endpoint Dialog box.
- Click on Create, and your private endpoint will be created.
Step 2: Installing dependencies in DevBox
We need to install the mongosh
shell tool to connect with the cluster.
Follow the below steps to do so:
- Install
gnupg
andcurl
if they are not already:
- Get the MongoDB public GPG key:
- Create a list file for MongoDB:
- Install the MongoDB Package:
- verify if
mongosh
is installed or not:
Step 3: Connecting to the Cluster
To connect to the MongoDB cluster, follow the below steps:
- Go to MongoDB Atlas.
- Go to Database > Clusters and select the Cluster you want to access.
- Click on Connect and choose the private endpoint option.
- Then Click on Shell, copy the connection string, and paste it into your DevBox:
- Enter the password when prompted, and you will see the MongoDB cluster is connected.
New MongoDB Cluster
If you need to make a new database cluster and access it through DevBox, then follow the below steps:
Step 1: Creating a Cluster
- Go to MongoDB Atlas.
- Go to Database > Clusters and click on Create.
- Choose between Dedicated or Serverless database cluster type.
- Enter the Instance name, Provider, and Region.
- Click on Create Deployment and give it time to deploy the infrastructure.
- Go to Security > Network Access and open the Private Endpoint tab.
- Click on Add Private Endpoint and choose your cloud provider. For this tutorial, we will be using Azure.
You must provide the billing information in the Edit Payment Method form if you don't have a payment method already configured for your organization.
- Click on Next and choose the Region where you want to deploy your endpoint.
- Enter your Resource Group Name, Virtual Network Name, Subnet Name, and the name you want to give to your endpoint.
- Copy and run this PrivateLink Endpoint Command where your Azure CLI is configured. Remember that you can only copy the command once Atlas finishes creating VNET resources in the background for internal use.
- Copy the Private Endpoint Resource ID and Private Endpoint IP Address and paste them into the MongoDB Private Endpoint Dialog box after creating the private endpoint.
- Click on Create, and your private endpoint will be created.
Step 2: Installing MongoDB Shell tool in DevBox
To connect with the cluster, we need to install the mongosh
shell tool.
Follow the below steps to do so:
- Install
gnupg
andcurl
if they are not already:
- Get the MongoDB public GPG key:
- Create a list file for MongoDB:
- Install the MongoDB Package:
- verify if
mongosh
is installed or not:
Step 3: Connecting with the Cluster
To connect to the MongoDB cluster, follow the below steps:
- Go to MongoDB Atlas.
- Go to Database > Clusters and select the cluster you want to connect to.
- Click on Connect and choose the private endpoint option.
- Then Click on Shell, copy the connection string, and paste it into your DevBox CLI:
- Enter the password when prompted, and you will see the mongosh shell if the connection is authenticated.