Here's how to create a free cluster and connect it to your project using the connection string
- Create an account on MongoDB Cloud Atlas
- You will be prompted right away to create a new project and org. You may leave all values as default and click
Continue
. - Three cards will show up next asking you to choose a cluster. Select the
Shared Cluster
- that's the one which is free. - The next screen is about details of the cluster. Make sure M0 Cluster Tier is selected. You may leave all values as default and click on
Create Cluster
- Wait for some time for the cluster to get ready and then click on
Connect
. - First thing you need to add it IP Address. Select
Add your current IP Address
if you are working on the project yourself only orAllow Access from Anywhere
. You may even manually add IP Addresses by clicking onAdd a different IP...
- Next up is Database user creation. You need to enter a username and password. For explanatory purposes, say I added them as
admin
andpass
respectively. - Next step asks you for a connection method. Select
Connect Your Application
and then copy the connection string that gets prompted and click close. You may even close your browser as you do not need to do anything further through the website. - Now open your project and create a
.env
file in the directory of your backend application and add a key value pair as follows:MONGO_URI=<paste your connection string that you copied>
The string looks like this: mongodb+srv://admin:<password>@cluster0.bqss1.mongodb.net/<dbname>?retryWrites=true&w=majority
In the connection string as shown above, you need to replace <password>
with the password you had created in step 7 and <dbname>
with a name that you would like to name your database.
So it would finally look like this for me (with username: admin, password: pass, dbname: todo)
mongodb+srv://admin:[email protected]/todo?retryWrites=true&w=majority
Do i Upload it to github?