I am new to mongodb, and I have created a todo list app using mongodb as a database. When user types something it saves to the mongoose collection, But when I try to delete the data from mongoose collection by onclick, It goes in order like If I click on the second button it will delete me the first data then second data and then third, It doesn't matter which button i am clicking It always goes in order(1,2,3,etc...)
Here is my code
app.js
router.delete('/Delete_Data', (request, response) => {
item.findOneAndDelete({}, (err, data) => {
if(err){
console.log(err);
return response.status(500).send();
}
else{
return response.json({data});
}
});
});
script.js
async function deleteLSItem(){
let options = {
method: 'DELETE',
headers: {
'Content-Type': 'application/json'
}
};
const response = await fetch('/Delete_Data' , options);
const data = await response.json();
console.log(data);
}
deleteLSItem()
is a delete button
<td class="table-buttons" id="margin-padding"><button class="btn btn-sm btn-primary delete-btn" onclick="deleteLSItem()"><i class="fa fa-trash" aria-hidden="true"></i></button><span>Delete</span></td>
question from:
https://stackoverflow.com/questions/65889230/how-to-delete-data-from-mongoose-collection-by-onclick 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…