Happy New Years Eve all,I'm coming across some really strange behavior:app.delete("/api-v1/tickets/:ticketID/notes/:noteID", auth, async (req, res) => {const ticketID = req.params.ticketID;const noteID = req.params.noteID;const ticket = {id : ticketID}const note = {id : noteID}const validTicketID = validateID(ticket);const validNoteID = validateID(note);if(!validTicketID.error){if(!validNoteID.error){try {let ticket = await Change.findById(ticketID)let note = await ticket.notes.id(noteID).remove()//let result = await ticket.notes.findByIdAndDelete(noteID)console.log(note)res.send(note);} catch (error) {res.status(404).send(error);}}else {res.status(500).send(validNoteID.error)}} else {res.status(500).send(validTicketID.error)}});};My function is attempting to delete a sub-document, a note attached to my ticket. I am able to get the ticket, and get the note in my ticket. However the remove() method simply does nothing. I also tried findbyIDAndDelete with the noteID, but that also just does nothing.I'm confused....Kind regards
Submitted December 31, 2018 at 02:05PM by sma92878
No comments:
Post a Comment