mongoose find by and delete
Campground.findByIdAndRemove(req.params.id, function(err){
if(err){
res.redirect("/campgrounds");
} else {
res.redirect("/campgrounds");
}
});
mongoose find by and delete
Campground.findByIdAndRemove(req.params.id, function(err){
if(err){
res.redirect("/campgrounds");
} else {
res.redirect("/campgrounds");
}
});
delete document mongoose
Tank.deleteOne({ size: 'large' }, function (err) {
if (err) return handleError(err);
// deleted at most one tank document
});
how to delete popultate subdocument mongoose
exports.feed = function (req, res) {
var userIds = req.user.friends;
Surf
.find({user_id: {$in: userIds}})
.populate('user_id', 'name boards') // added boards
.populate('friends', 'name')
// .populate('board_id', 'name size') // can't do this as discussed
.exec(function (err, surfs) {
if (err) {
return handleError(res, err);
}
surfs.forEach(function (surf) {
surf.boardInfo = surf.user_id.boards.id(surf.board_id)
});
// TODO: now remove the surf.user_id.boards.
return res.json(200, surfs);
});
};
mongoose remove
const res = await Character.remove({ name: 'Eddard Stark' });
res.deletedCount; // Number of documents removed
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us