deleteOne from mongoDB with mongoose in object display page support

  ejs, express, javascript, mongodb, mongoose

i am trying to remove a particular ‘ticket’ in this case from the database. the page displays a table of all the tickets and their seat name and price, and a delete button(form). However, the delete function (regardless of which one i select) only deletes the first ticket in the list.

here is controller function:

    Ticket.findOneAndDelete(req.params.id, function(err) {
      console.log('deleting button works in Tickets router')
        res.redirect('/tickets');
      });
    };

router:

router.post('/tickets/:id', ticketsCtrl.delete)

ejs snippet:

        <tr>
          <td><%= t.seat %></td>
          <td><%= t.price %></td>
          <td>
          <form id="delete-ticket-form" method="POST"
          action="/tickets/<%= t._id %>">
          <input type="submit" value="X">
        </td>
        </tr> 

Source: Ask Javascript Questions

LEAVE A COMMENT