提醒:由於看到這系列鐵人訂閱人數漸漸變多,標記一下這些內容是在「非常萌新時期」所寫,更多技術內容請參考我的 Github,歡迎跟我一起討論 ^ ^
昨天完成了 新增 這個部分,今天繼續把 更新、刪除 完成。
a(href=author.url+'/delete') Delete author
 (err, results) => {
    if (err) { return next(err) }
    if (results.author === null) { 
      res.redirect('/catalog/authors')
    }
p #{author.birthDay} - #{author.deathDay}
if author.date_of_birth && author.date_of_death
    p= `享年: ${author.lifespan}`
findByIdAndRemove:以參數1的ID搜尋並刪除該資料,並完成參數2 的 callback(這邊導回作者列表)。req.body: 用以抓取 request 的提供的資訊。Author.findByIdAndRemove(req.body.authorid, (err) => {
  if (err) { return next(err) }
  res.redirect('/catalog/authors')
})
a(href=book.url+'/update') Update Book
checked,已將已有資訊附上。for (let i = 0; i < results.genres.length; i++) {
  for (let j = 0; j < results.book.genre.length; j++) {
    if (results.genres[i]._id.toString() === results.book.genre[j]._id.toString()) {
      results.genres[i].checked = 'true' } } }
book.author 有些許差異。其回傳一個 object)
for author in authors
  if book
    option(
      value=author._id
      selected=(
        author._id.toString()===book.author._id
        || author._id.toString()===book.author
      ) ? 'selected' : false
    ) #{author.name}
const book = new Book({
 ( ... )
  _id: req.params.id 
})
findByIdAndUpdate() 以更新特定 ID 的資料,就大功告成啦:Book.findByIdAndUpdate(req.params.id, book, {}, (err, thebook) => {
  if (err) { return next(err) }
  res.redirect(thebook.url)
})