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:

  1. Go to MongoDB Atlas and Create an Account
  2. Create a Free Shared Cluster, customizing the location and name if you wish
  3. Wait for the cluster to be created → Usually about 5 minutes
  4. Go to Database Access, create a new user with a password (copy and paste this somewhere) and give the user read/write previlages
  5. Go to Clisters, Click Collection, Click Add my Own Data, and Create a Database and Collection, note down the database name
  6. Go to Network Access, Add IP Address, and add your IP address here, or allow access from anywhere
  7. Go to Clusters, Connect, Choose 'Connect with App', Copy the URI and paste it somewhere
  8. Edit the URI, to add the database name and password

Glitch Setup

  1. Open the Github Repostiory and copy the link
  2. On Glitch Click 'New Project', Import from Github, and paste in the link
  3. Go .env and create a new variable to store the URL (with the password and database name edited in)
  4. 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