https://youtu.be/NA1w1oWtUe8
This is a guide to setting up the database and glitch project for the MongoDB and Mongoose Course on freeCodeCamp. I found this really difficult to get working, and the guide seems quite outdated, so this is how I've done it.
MongoDB Setup:
- Go to MongoDB Atlas and Create an Account
- Create a Free Shared Cluster, customizing the location and name if you wish
- Wait for the cluster to be created → Usually about 5 minutes
- Go to Database Access, create a new user with a password (copy and paste this somewhere) and give the user read/write previlages
- Go to Clisters, Click Collection, Click Add my Own Data, and Create a Database and Collection, note down the database name
- Go to Network Access, Add IP Address, and add your IP address here, or allow access from anywhere
- Go to Clusters, Connect, Choose 'Connect with App', Copy the URI and paste it somewhere
- Edit the URI, to add the database name and password
Glitch Setup
- Open the Github Repostiory and copy the link
- On Glitch Click 'New Project', Import from Github, and paste in the link
- Go .env and create a new variable to store the URL (with the password and database name edited in)
- This can then be accessed as process.env.<VARIABLE_NAME>
<aside>
❗ For me, Glitch doesn't allow the URI to be stored as an environment variable. Try console logging. If it returns undefined, wait a couple hours and try again. If it is still not working, store your password as a variable instead, and use it to construct a string with the URI. Alternartively, you can simply put the entire URI string in the source code, although this a really bad idea.
</aside>
To submit challenges, click 'Share' and copy and paste the Live App link.
Concepts
process.env