Implementing the routes
Until now, we implemented our handlers as dummy functions that don’t do anything at all. This section will teach us how to save, retrieve, modify, and delete actual to-do tasks using MongoDB as the data source. For every subsection, we will examine only one handler, knowing that it will replace the same handler we already defined in ./routes/todos/routes.js
.
Unique identifiers
This section contains several code snippets and commands to issue in the terminal. It is important to remember that the unique IDs we show here are different from the ones you will have when testing the routes. In fact, the IDs are generated when a task is created. Change the command snippets accordingly.
We will start with createTodo
since having items saved on the database will help us implement and test the other handlers.
createTodo
As the name implies, this function allows users to create new tasks and save them to the database. The following code snippet defines...