Now that's you've learned about non-relational databases and how to structure them with schemas, let's practice looking at actual data sets and creating a structure based on the documents inside of them.
- MongoDB
- Mongoose
- Data Modeling & Schemas
- Fork and clone this repository.
- Change into the new directory.
- Fulfill the listed requirements.
Starter code is available in the data-sets
directory. You are required to turn
in your submission by making a pull request on the original repository.
Unless otherwise specified on the calendar or by an instructor, homework is due the next morning by 9:00am.
In the data-sets
directory, you'll find a few subdirectories. Each of these
subdirectories contains a json
file with a data set. Based on the data set,
create a file representing each model that includes:
- Proper naming convention of the model's
js
file - A variable
Schema
set equal tomongoose.Schema
- Model defined using the
Schema
method - Properties that correlate with the data set
- Appropriate data types and validation for each property
- Export schema using
module.exports
For example, for the data set:
[
{
"name": "Erin",
"hometown": "Villanova, PA",
"yearsInDC": 8,
"lovesToCode": true
}
];
Your model file (named Person.js
or something else semantic, should look like
this:
const Person = new mongoose.Schema({
name: String,
hometown: String,
yearsInDC: Number,
lovesToCode: Boolean
})
module.exports = mongoose.model("Person", Person)
For the examples that require parent and child schemas, use the Author and Cookbook solution that we learning in class as a reference! Hint: An array of objects will be a clue!
How can you tell if your model works?
Create an index.js
file (or something) inside the folders for each prompt.
Inside that file, import your model and import the seed data. Insert the seed
data into your database with your model. Then check it in the MongoDB shell.
If the data you see in MongoDB matches the data in the json file, then your model is working! If you get an error or some data is missing, then you have some work to do still.
Take a moment to refamiliarize yourself with the Plagiarism policy. Plagiarized work will not be accepted.
- All content is licensed under a CCBYNCSA 4.0 license.
- All software code is licensed under GNU GPLv3. For commercial use or alternative licensing, please contact [email protected].