this is my route .js delete function
//Delete the country info
router.delete('/:id/deleteans/:answersId', (req, res, next) => {
Forum.findOneAndDelete({_id:req.params.id},{$pull: {answers: {_id: req.params.answerId}} }, function (err, result) {
if (err) {
res.json(err);
}
else {
res.json(result);
}
});
});
my have api like this,
{
"success": true,
"forums": [
{
"createdAt": "2018-11-24T07:00:58.716Z",
"_id": "5bf8f907f6108603f4eb8c28",
"title": "how to chs right prgm",
"body": "zxsdcfghj",
"createdBy": "[email protected]",
"answers": [
{
"createdAt": "2018-11-24T07:00:58.716Z",
"_id": "5bf8f939f6108603f4eb8c29",
"content": "asdfghjmksadfghjk",
"createdBy": "[email protected]"
}
],
"__v": 1
}
]
}
i want to delete that particular answer id, but my delete function , delete question also . i don't know where i did mistake please help me.