comment: 'hi'
replies: array
likes: array
I have to remove comment field and every time I delete it deletes the whole collections.
This is the code
deleteComment: async (root, { commentID, comment}) => {
try{
const deleteComment = await CommentModel.findOne(
{_id:commentID}
);
if(deleteComment) {
const remove = await CommentModel.deleteOne(comment)
return(remove)
}
} catch(err) {
console.log(err)
}
},
Just delete by ID.
CommentModel.deleteOne({_id: new mongodb.ObjectID(commentID)});
I'm assuming you are using the mongodb
npm package.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.