I have document named Category
and subdocument with an array as Items
. When I remove the subdocument, I am unable to confirm either it is deleted or not. Either the provided subdocument id was correct or not.
If I provide invalid item id (not available in database), it does not give me an error or some clue.
Code Modified
router.delete('/:category/:item', async (req, res) => {
let categoryId: number = req.params.category;
let itemId: number = req.params.item;
CategorySchema.findOneAndUpdate(
{ category_id: categoryId },
{ $pull: { items: { item_id: itemId } } },
{ new: true }, function(err, doc, raw) {
console.log(raw) // undefined
});
res.status(200).send(itemId);
})
Please help to improve!!!
Regards