Last Sync: 2022-08-30 15:00:04

This commit is contained in:
tactonbishop 2022-08-30 15:00:04 +01:00
parent 196b9f4112
commit 242157ae84

View file

@ -80,7 +80,7 @@ const courseSchema = new mongoose.Schema({
With this established we can remove our local array as we are ready to start getting our data from the database:
```diff
const Course = new mongoose.model('Course', courseSchema);
const Course = mongoose.model('Course', courseSchema);
- const courses = [
- {
@ -191,3 +191,17 @@ router.delete("/:id", (req, res) => {
res.send(course);
});
```
```diff
router.delete("/:id", async (req, res) => {
const courseToDelete = await Course.findByIdAndRemove(req.params.id)
if (!course) return res.status(404).send("A course with the given ID was not found");
- courses.indexOf(course);
- courses.splice(index, 1);
res.send(course);
})
```