I was learning about removing a collection from MongoDB with express. I know I have to use app.delete when deleting something, but the way I see my code, it's actually Todos, or MongoDB that does deleting, by its deleteOne function that does anything relating to removing the content. So I guess this is not a question about how to do, but rather I want to understand how its actually work. Does the same question apply to app.Method(), like post for example. Can get replace delete in certain situations, or what is the benefit of specifying the method.
I tried changing everything to "get", that means app.delete -> app.get, and $.ajax type to get also, and it works perfectly fine.
This is the js file:
$(document).ready( () => {
$('.delete-todo').on('click', (e) => {
$target = $(e.target);
const id = $target.attr('data-id');
$.ajax({
type: 'DELETE',
url: '/todo/delete'+ id,
This is app.js
app.delete('/todo/delete:id', (req, res, next) => {
const query = {_id: ObjectID(req.params.id)}
Todos.deleteOne(query, (err, response) => {