delete one mongoose nodejs code example
Example 1: deleteOne mongoose
Tank.deleteOne({ size: 'large' }, function (err) {
if (err) return handleError(err);
});
Example 2: how to delete popultate subdocument mongoose
Surf
.find({user_id: {$in: userIds}})
.populate('user_id', 'name boards')
.populate('friends', 'name')
.exec(function (err, surfs) {
if (err) {
return handleError(res, err);
}
surfs.forEach(function (surf) {
surf.set('boardInfo', surf.user_id.boards.id(surf.board_id), {strict: false});
});
return res.json(200, surfs);
});
Example 3: 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')
.populate('friends', 'name')
.exec(function (err, surfs) {
if (err) {
return handleError(res, err);
}
surfs.forEach(function (surf) {
surf.boardInfo = surf.user_id.boards.id(surf.board_id)
});
return res.json(200, surfs);
});
};