Comprehensive guide for connecting to a MongoDB Cluster from your DevBox.
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.
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.
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.
We need to install the mongosh
shell tool to connect with the cluster.
Follow the below steps to do so:
Install gnupg
and curl
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:
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.
To connect to a database cluster, please make sure it is allowed inbound access from anywhere.
To check and configure the same, follow the below steps:
Go to MongoDB Atlas.
Go to Security > Network Access and click on Add IP Address.
In the Access List Entry, enter 0.0.0.0/0
to allow inbound access from anywhere.
To connect with the Cluster, we need to install the mongosh
shell tool.
Follow the below steps to do so:
Install gnupg
and curl
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:
You can skip this step if you prefer to use password-based authentication. We are using an X.509 certificate authentication to add an extra layer of security because a shared type cluster allows all internet traffic, which also requires code changes.
To add a layer of security, we will authenticate it with an X.509 certificate. You may follow the below steps to do so:
Go to Database Access and click on Add new database user.
Select Certificate and enter the username.
Check the Download certificate when the user is added and then choose the certificate expiration duration.
Click on Add user and save the certificate to your DevBox.
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 then choose the Standard connection and click on Shell.
Choose the Password (SCRAM) option and copy the connection string and paste it into your DevBox CLI:
Choose the X.509 Certificate option and copy the connection string and paste it into your DevBox CLI:
You will see the mongosh shell if the connection is authenticated.
If you need to make a new database cluster and access it through DevBox, then follow the below steps:
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.
To connect with the cluster, we need to install the mongosh
shell tool.
Follow the below steps to do so:
Install gnupg
and curl
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:
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.
Go to MongoDB Atlas.
Go to Database > Clusters and click on Create.
Choose Shared 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 IP Access List tab.
In the Access List Entry, enter 0.0.0.0/0
to allow inbound access from anywhere.
To connect with the cluster, we need to install the mongosh
shell tool.
Follow the below steps to do so:
Install gnupg
and curl
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:
You can skip this step if you prefer to use password-based authentication. We are using an X.509 certificate authentication to add an extra layer of security because a shared type cluster allows all internet traffic, which also requires code changes.
To add a layer of security, we will authenticate it with an X.509 certificate. You may follow the below steps to do so:
Go to Database Access and click on Add new database user.
Select Certificate and enter the username.
Check the Download certificate when the user is added and then choose the certificate expiration duration.
Click on Add user and save the certificate to your DevBox.
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 then choose the Standard connection and click on Shell.
Choose the Password (SCRAM) option and copy the connection string and paste it into your DevBox CLI:
Choose the X.509 Certificate option and copy the connection string and paste it into your DevBox CLI:
You will see the mongosh shell if the connection is authenticated.