Week 7 - Data driven websites & MongoDB

Wednesday Agenda

  • Relationship maintenance and use
  • Team DB Setup

Monday

Tuesday

Thursday

MongoDB

MongoDB is a document based database system. One way to make use of it is via the MongoDB cloud, which allows you to spin up and use a database that lives on a managed server.

Mongoose

Mongoose is an Object Database Modeling tool that helps connect object-oriented JavaScript code to MongoDB database collections to store data. We will be using it to do all of the actual work of reading/writing to MongoDB.

Now use this Checklist for DB Setup to work through setting up an account on the MongoDB cloud and testing it out using the cs290 code samples.

Reference

Mongoose Schemas and Models

When using Mongoose, the way we define the data we want to store in our database is via creating Schemas. Those schemas are then used to create Models, which are an object we use to create objects of that type and to interact with the database.

References

Representing and Managing Relationships

You won't need to set up relationships for your assignment this week as you will only be working with a single data type. You will however need to use these ideas in your group project.

So you may want to just watch the videos for now, and spend time looking at the code when you go to do this work on your final project.

When the objects described by different schemas have relationships to each other, we have to decide how to represent those relationships. This video describes our options:

Once we decide how to represent our data, we need to figure out a way to set up some relationships in the data we load into our database:

Then, as we work with the data in our program, we have to do work to retrieve the data connected by those relationships. Fortunately, there are a couple of tricks that can make this easy to do:

Putting it Together

Once we have some data in our database, we can use Mongoose to retrieve that data and then build dynamic web pages from it. This video demonstrates putting the pieces together:

Extra References

MDN has a series of posts that walk through a bigger version of a project like the ones we are building. (It is the source of the library examples I sometimes use to supplement the Hero/Teams examples.)

Here are the two pages on setting up and using a database: