Deleting a team is extremely easy. To do this, we will call the remove built-in method of the Team model. Add the following code:
...
.delete((req, res, next) => {
let id = req.params.id
Team.remove({_id: id})
.then(result => res.json(result))
.catch(err => next(err))
})
module.exports = api
Now, let's test things out. Execute the following command:
$ curl -X DELETE http://localhost:3000/teams/5a662fbf728726072c6298fc
{"n":1,"ok":1}
The output is a bit different now; we received a JSON object with two params:
- n: The number of documents removed
- ok: 1 if the operations were successful or 0 if not
Awesome! Now we have our Rest API to manage our teams ready, but there is a key missing piece in our API that we did not take care of, and that is security. We will make our API secure by adding an authentication and authorization layer in subsequent chapters. Keep reading!