Giter VIP home page Giter VIP logo

monarch-lab's Introduction

General Assembly Logo

Monarchs: A Seeding Exercise

So far in this unit, you have spent some time creating models and seeding data into your database. Seeding data can get a little more complicated when you have nested models, or models that contain subdocuments consisting of other collections of data.

In this exercise, you will need to consider how to structure your Schema, and subsequently seed your database so that we can nest these two data sets.

You have been provided with starter code that includes raw JSON data. Your objective is to create models and seed the desired data a local database using Mongoose, making sure each monarch contains the kingdom over which they reigned.

Prerequisites

  • Node & NPM
  • MongoDB
  • Mongoose
  • Data Modeling
  • Database Seeding

Instructions

  1. Fork and clone this repository.
  2. Change into the new directory.
  3. Install dependencies.
  4. Fulfill the listed requirements.

Please turn in your submission by the deadline on your cohort calendar.

Requirements

Before you begin, take some time to familiarize yourself with the data provided. Once you have done this,fulfill the requirements below.

Hint: You will not need to make any adjustments to the raw data or db/connection.js files. You will only be working with your models and the files located in the db/seed directory.

  1. Create a Monarch model that includes the following properties and their appropriate data types: name, house, start, end, endReason and kingdom.

  2. Create a Kingdom model that includes the following properties and their appropriate data types: title and extract.

  3. In 00--seed-collections.js, map throught the monarch raw data (from the JSON) to create a new array of objects that only includes the properties needed in the Monarch model.

  4. In the same file, follow a similar process to map through the kingdom raw data to create a new array of objects that only includes the necessary properties.

  5. Still in 00--seed-collections.js, use the new arrays of monarch and kingdom data to seed their respective collections in your local database.

  6. Use the command node db/seed/00--seed-collections.js and confirm your local database has the collections for both Monarchs and Kingdoms.

    At this point, there will not be a "kingdom" field for each monarch.

  7. In 01--seed-nested-models.js seed your data in a way that updates the monarchs collection to include the kingdom over which each monarch reigned.

    One way to do this is to get all of the Monarchs from the database (Hint: using Mongoose). This is important because we can save each document when we update it to add the kingdom as we iterate through the array of documents we get from the Mongoose query.

    If we import the original raw JSON for each Monarch, we can use the "name" property for each Monarch document (from you database) to find that monarch's raw JSON data.

    Since the JSON has the String name of the Kingdom, we can use a Mongoose query for Kingdoms (from your database) to find that Kingdom, and then set the monarch's "kingdom" property to the value of the Kingdom document, and presto!

  8. Use the command node db/seed/01--seed-nested-models.js to seed the nested model fields in your local database.

  9. Open your Mongo Shell and check the database to verify.

Plagiarism

Take a moment to refamiliarize yourself with the Plagiarism policy. Plagiarized work will not be accepted.

  1. All content is licensed under a CC­BY­NC­SA 4.0 license.
  2. All software code is licensed under GNU GPLv3. For commercial use or alternative licensing, please contact [email protected].

monarch-lab's People

Contributors

tomatohammado avatar erinkelley27 avatar clarknoah avatar

Watchers

lissa warshaw avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.