I have a MongoDB collection named "Members" which stores data for each member including first name, last name, and an autogenerated Object ID. I am able to retrieve the data using ExpressJS and display it with VueJS. While my get and post methods are working fine, I am struggling to implement a delete method. How can I identify the specific member that the user clicks on in order to delete it? Below is a simplified version of my code:
<form action="/delete" method="delete">
<ul>
<li v-for="(value, index) in allTeamMembers">
{{ 'Member: ' + value }}
<button type="submit">Delete</button>
</li>
</ul>
</form>
expressApp.delete('/delete' , function (request, response) {
MongoClient.connect(url, function (err, db) {
if (err) throw err;
let dbo = db.db(dbName);
let myquery = {first_name: 'Tobias'};
dbo.collection("Members").deleteOne(myquery, function (err, obj) {
if (err) throw err;
console.log("1 document deleted");
db.close();
});
});
});
Currently, my query only targets members with the first name "Tobias", but I need to dynamically target the clicked element from the list. Any suggestions on how to achieve this?