- 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.
Use Node.js, Express.js and Mongoose.js to build an API that queries data persisted in a MongoDB database.
- Fork and Clone this repository.
- CD into the folder where you cloned the repository.
- Type
yarn
ornpm install
to download all dependencies listed insidepackage.json
.
- 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.
- To start the server, type
yarn start
ornpm 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.
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.
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
.
- only include:
- 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.
- Use
create-react-app
to create an application inside the root folder, name itclient
. - 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.
Stop the MongoDB database server when not in use to save computer resources.