Assignment following MongoDB Intro Lessons. Due September 27, 2021
Mongo Express Node suggestion-box-hw
Use Postman and Robo 3T to test your routes Use MongoDB and Mongoose and name database suggestion-hw Use Async and Await (Don't forget the try and catch block) Use controllers for business logic.
- Remember to be inside folder and npm i*
- Only .gitignore the node_modules
- Create an express server using express-generator:
- express suggestion-box-hw --view=ejs
- Delete all view related items
- Connect to mongodb with mongoose.
- Remember to name database suggestion-hw.
- In routes folder create a suggestions folder
- Then create suggestionRouter.js inside suggestion folder
- Make sure you connect it through app.js with the path '/api/suggestions'
- In suggestion folder,
- Create model folder
- Controller folder.
- Then create suggestionRouter.js inside suggestion folder
- In model folder,
- create a file called Suggestion.js:
- Build a schema for Suggestions called SuggestionSchema
- Title
- string
- lowercase
- unique
- required
- Author
- string
- lowercase
- Suggestion
- string
- lowercase
- required
- Likes
- number
- default to 0
- Anonymous
- boolean
- TimeCreated
- date with default Date.now
- Title
- Build a schema for Suggestions called SuggestionSchema
- create a file called Suggestion.js:
- create a file called suggestionController.js
- getAllSuggestions
- getSingleSuggestion
- get one suggestion based on id using parameters
- createSuggestion- does not need id or time from user
- updateSuggestion- user can only update title and suggestion
- deleteSuggestion - suggestion deletes based on id
- Hook it up to suggestionRouter.js
- GET /all-suggestions
- GET /single-suggestion
- POST /create-suggestion
- UPDATE /update-suggestion
- DELETE /delete-suggestion
- Make a GET /by-author-suggestion using query
- getSuggestionsByAuthor- if i query a author's name i should get a list of their suggestions
in url www.shop.com/products/?item=shoes in code req.query.item equals shoes