Create a CRUD App with Node and MongoDB

Editing Events

Editing events is going to use two of the mongoose methods that we used earlier. We'll use Event.findOne() and the .save() method.

Here's an example:

// finding a current event
Event.findOne({ slug: req.params.slug }, (err, event) => {
  // updating that event
  event.name        = req.body.name;
  event.description = req.body.description;

  event.save((err) => {
    if (err)
      throw err;

    // success flash message
    // redirect back to the /events
    req.flash('success', 'Successfully updated event.');
    res.redirect('/events');
  });
});