S
S
Sergeev1ch2020-11-09 16:08:36
MongoDB
Sergeev1ch, 2020-11-09 16:08:36

How to delete an entry in the database by _id?

There is a database of users.

spoiler
5fa93d6871867864516614.png

I want to make it so that when you click on the cross, user data is deleted.
spoiler
<form action="/personalList" method="post">
    <td><input type="hidden" name="id" value="<%= item._id%>"><input type="submit" value="&#10006" ></input></td>
    </form>

When loading from the database, the user's _id is passed to the hidden input and by the button it is returned to the server. Most likely an attempt at data type conversion. Tried many solutions. Perhaps someone knows how to implement the delete function?

UPD Solved the issue.
personal.remove({_id: req.body.id})
change to
personal.remove({_id: req.body.id}, (err, results) => {
  })

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question