Git Product home page Git Product logo

mongo-iv's Introduction

Mongo IV Project

Topics

  • Importing Data from JSON files.
  • Exporting Data to JSON files.
  • Modeling One to Many Relationships.
  • Data Population in One to Many Relationships.
  • Querying Data.
  • Enabling Cross Origin Resource Sharing in Node.js APIs.

Assignment

Use Node.js, Express.js and Mongoose.js to build an API that queries data persisted in a MongoDB database.

Download Project Files and Install Dependencies

  • Fork and Clone this repository.
  • CD into the folder where you cloned the repository.
  • Type yarn or npm install to download all dependencies listed inside package.json.

Import Sample Data

  • Windows users follow this tutorial to add the MongoDB bin folder to your path. Linux and MacOS users should be ready to go. If you don't have Windows 10, follow the section for your version of windows on this tutorial instead.
  • We have provided six JSON files with sample data inside the /data folder.
  • Use the mongoimport utility to import all the data into your local instance of MongoDB. Please make sure the MongoDB server is running before starting the import process.
  • In a terminal or command prompt window, navigate to the data folder and run the following command for each JSON file.
  mongoimport --db starwars --collection characters --file characters.json

This code imports the characters data into the characters collection of the starwars database. Modify to do the same for all six files.

MongoDB will automatically create the database and the collection.

  • After importing all files, open MongoDB compass and verify that the data was imported successfully into the starwars database. If you get errors, please reach out to your assigned PM.

Now that we have the sample data loaded, it is time to work on the API.

Start the API and Implement Requirements

  • To start the server, type yarn start or npm start from the root folder (where the package.json file is). The server is configured to restart automatically as you make changes.
  • Take some time to study the code provided.
  • Add the code necessary to implement the API requirements.
  • Test the API using Postman as you work through the exercises.

Configure relationships on the provided mongoose Schemas.

Each Schema is configured to work with the data imported into the corresponding collection on the database, but is missing the field(s) needed for the relatioships.

Write endpoints to perform the following queries.

Return a list of all films. (/api/films)

  • order by episode.
  • populate character information.
    • only include: _id, name, gender, height, skin_color, hair_color and eye_color.
  • populate planets, include: name, climate, terrain, gravity and diameter.

Find all films produced by Gary Kurtz (/api/films?producer=gary+kurtz)

Find all films released in 2005. (/api/films?released=2005)

Given a character id, (/api/characters/:id)

  • find the character and return it.
  • populate the character's homeworld.
  • add a movies property that should be an array of all the movies where the character appeared.

Find all vehicles driven by a given character. (/api/characters/:id/vehicles)

Find all female characters taller than 100cm (/api/characters?minheight=100)

Given a planet Id find all characters born in that planet and all native species. (/api/planet/:id)

Write an endponint (PUT to /api/species/populate/charactes) that will go over the list of all species and using the list of character_keys add a characters field that references the character with the corresponding key in the characters collection. The characters field in species must be of type ObjectId and reference the _id on the characters collection.

Stretch Problems

  • Use create-react-app to create an application inside the root folder, name it client.
  • From the React application connect to the /api/films endpoint in the API and show the list of Characters
  • Style the list of characters however you see fit.
  • Add as many CRUD endpoints as you can for the Resources to make it a full API.

Additional Notes

Stop the MongoDB database server when not in use to save computer resources.

mongo-iv's People

Contributors

luishrd avatar

Watchers

James Cloos avatar AnthonyCatalfo 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.