I am new to mongodb, I am running through a problem, Like I want to delete the data dynamically by onclick but it shows me an error Argument passed in must be a single String of 12 bytes or a string of 24 hex characters
My code is
app.js
router.delete('/Delete_Data/:itemIndex', (request, response) => {
const itemIndex = request.params.itemIndex
item.findOneAndRemove({_id: itemIndex}, (err, data)=> {
if(err){
console.log(err);
return response.status(500).send();
}
else{
console.log({data});
return response.json({data});
}
});
});
page1.js
I have used fetch DELETE method
async function deleteLSItem(itemIndex){
let options = {
method: 'DELETE',
headers: {
'Content-Type': 'application/json'
}
};
const response = await fetch('/Delete_Data/'+itemIndex, options);
const data = await response.json();
console.log(data);
}
question from:
https://stackoverflow.com/questions/65920473/how-to-delete-dynamic-data-from-mongoose-collection-by-onclick 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…