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 find by and delete

Campground.findByIdAndRemove(req.params.id, function(err){
      if(err){
          res.redirect("/campgrounds");
      } else {
          res.redirect("/campgrounds");
      }
   });
Comment

MONGOOSE delete

Modelname.findOneAndDelete({ id: id })
Comment

PREVIOUS NEXT
Code Example
Javascript :: jquery get text of input 
Javascript :: sort array without changing original array 
Javascript :: javascript squared 
Javascript :: regex is empty string javascript 
Javascript :: window onscroll position fixed position in jquery 
Javascript :: angular bind checkbox 
Javascript :: sort array of objects by string property value 
Javascript :: date format in react js 
Javascript :: moment get weekday name 
Javascript :: react native text get number of lines 
Javascript :: jquery add remove class timer 
Javascript :: react router redirect 
Javascript :: lodash pluck items 
Javascript :: Sort number in descending order 
Javascript :: Prevent Double Submit with JavaScript 
Javascript :: javascript date is an object 
Javascript :: diff two arrays javascript 
Javascript :: indexOf by object key 
Javascript :: select2 find option by value 
Javascript :: js multiple url fetch 
Javascript :: laravel jquery csrf 
Javascript :: react navigation header background color 
Javascript :: checkvalidity 
Javascript :: what 1hr in milliseconds in javascript 
Javascript :: discord.js remove reaction 
Javascript :: duplicate value removed in array of object in javascript 
Javascript :: capitalise first letter js 
Javascript :: regex char and number 
Javascript :: antd modal hide ok button 
Javascript :: jquery edit iframe content 
ADD CONTENT
Topic
Content
Source link
Name
7+2 =