Connect REST API with MongoDB 'Relational Schema' using Mongoose - Lab Task 8

In previous task we didn't saved the data in MongoDB, lets save in this task.

Saving and fetching simple entities with primitive fields in MongoDB is already demonstrated in lecture, as you know. In this task, you are supposed to update the REST API implemented in Express to connect to MongoDB for CRUD operations. The updated code shall comply with below mentioned schema updates and requirements:
  1. Make new REST endpoint for 'course' resource with attributes like: id, code, name and pre_requisite_code. The web server shall expose all CRUD operations by RESTful Services.
  2. Add 'courses' field in 'student' object / schema as an array of 'course' objects. The RESTful Service of 'student' resource shall process the 'courses' field too i.e. it shall process POST/PUT request to add and update nested fields and the 'student' object returned in reponse to GET request shall hold 'courses' and 'phone_numbers' arrays, in addition to other basic fields.
  3. Define the model and schema in such a way that only course IDs shall be saved in 'student' object in MongoDB. The course details shall be fetched from 'courses' collection by Mongoose.
  4. In almost all cases, the 'address' would be unique for each student (multiple students living at same address would be very few, lets save their address in denormalized way). So the 'address' field shall be defined in schema to be saved within 'student' object in MongoDB i.e. as nested object and not in a separate collection.
Please remember, RESTful Service, REST API or REST Endpoint means, the web server shall process HTTP GET, POST, PUT and DELETE request by performing corresponding operations are server on the specified resource e.g. Person, Products, etc. And it shall accept, process and generate data in standard format e.g. JSON.