Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Mongoose DELETE

// Delete a user by username
app.delete('/users/:Username', (req, res) => {
  Users.findOneAndRemove({ Username: req.params.Username })
    .then((user) => {
      if (!user) {
        res.status(400).send(req.params.Username + ' was not found');
      } else {
        res.status(200).send(req.params.Username + ' was deleted.');
      }
    })
    .catch((err) => {
      console.error(err);
      res.status(500).send('Error: ' + err);
    });
});
Comment

mongoose delete request

// The "todo" in this callback function represents the document that was found.
// It allows you to pass a reference back to the client in case they need a reference for some reason.
Todo.findByIdAndRemove(req.params.todoId, (err, todo) => {
    // As always, handle any potential errors:
    if (err) return res.status(500).send(err);
    // We'll create a simple object to send back with a message and the id of the document that was removed
    // You can really do this however you want, though.
    const response = {
        message: "Todo successfully deleted",
        id: todo._id
    };
    return res.status(200).send(response);
});
Comment

MONGOOSE delete

Modelname.findOneAndDelete({ id: id })
Comment

PREVIOUS NEXT
Code Example
Javascript :: format date js 
Javascript :: add event listener on width screen resize 
Javascript :: esversion 9 
Javascript :: File line by line reader Node js 
Javascript :: chrome add a javascript bookmark 
Javascript :: angular cli generate component 
Javascript :: js remove element from array 
Javascript :: javascript random numbers 
Javascript :: calculate today date javascript 
Javascript :: vue inline style bind 
Javascript :: check if all elements in array are true javascript 
Javascript :: referenceerror window is not defined ckeditor 
Javascript :: jqurey text contains selector 
Javascript :: how to integrate redux dev tool to react application 
Javascript :: how to make a button execute a javascript function 
Javascript :: regex repeat n times 
Javascript :: javascript math.random 
Javascript :: server status minecraft javascript 
Javascript :: How to Set Active Tab in jQuery Ui 
Javascript :: js C:fakepath 
Javascript :: toast angular 
Javascript :: chosen-select disable 
Javascript :: javascript detect if object is date 
Javascript :: Cannot resolve taglib with uri http://java.sun.com/jsp/jstl/core 
Javascript :: reactbootstrap multiselect 
Javascript :: js array add element 
Javascript :: how to remove comma from array in javascript 
Javascript :: hover effect in material ui 
Javascript :: get name of class javascript 
Javascript :: javascript dynamic import 
ADD CONTENT
Topic
Content
Source link
Name
9+2 =