I'm trying to delete a listing from my mongoDB collection via mongoose react and axios , i've managed to make it work one time but somehow i messed it up and couldent figure out why , thanks for the help!
React Function
const handleDeleteProperty = async () => {
let title = document.getElementById('title').value
try{
const res = await axios.delete('/delete', title);
if(res.data.success){
alert(res.data.msg);
}
}
catch(err){
console.error(err);
}
}
React function evoking
<button onClick={handleDeleteProperty}>DELETE LISTING</button>
Backend(List is my mongoose schema)
app.get("/delete", (req, res) => {
});
app.delete('/delete', async (req, res) => {
try{
await List.findOneAndRemove(req.body.title);
return res.status(200).json({ success: true, msg: 'Product Deleted' });
}
catch(err){
console.error(err);
}
});
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…