ошибка mongoose nodejs при запуске обновления

#node.js #express #mongoose

#node.js #экспресс #mongoose

Вопрос:

Я пытался использовать crud, но получал ошибку ссылки в nodejs mongoose. Ошибка: введите описание изображения здесь Пожалуйста, помогите, я пытаюсь использовать CRUD в nodejs и mongoose. Ошибка, возникающая от имени администратора, не определена AdminController

 router.get('/edit/:id', async (req,res) => {
    const { id } = req.params;
    const admin = await Admin.findById(id);
    res.render('table', {
        admin
    });
});

router.get('/edit/:id', async (req,res) => {
    const { id } = req.params;
    await Admin.update({_id: id}, req.body);
    res.redirect('/seo');
});
  

table.ejs

 <a href="/edit/<%= admins[i]._id%>" class="btn btn-primary" data-toggle="modal" data-target="#editModal" class="modal-btn" id="btn_modal">Edit</a>
<div class="modal" id="editModal" tabindex="-1" role="dialog" aria-labelledby="editModalLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="editModalLabel">Edit</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">amp;times;</span>
        </button>
      </div>
      <div class="modal-body">
        <form action="/edit <%= admin._id %>" method="POST" id="myForm">
          <div class="form-group">
            <input type="text" class="form-control" placeholder="Title" name="title" value="<%= admin.title%>">
          </div>
          <div class="form-group">
            <input type="text" class="form-control" placeholder="URL" name="url" value="<%= admin.url%>">
          </div>
          <div class="form-group">
            <input type="text" class="form-control" placeholder="Description" name="description" value="<%= admin.description%>">
          </div>
          <div class="form-group">
            <input type="text" class="form-control" placeholder="Keywords" name="keywords" value="<%= admin.keywords%>">
          </div>
        </form>
  

Комментарии:

1. Обратите внимание, что таблица. ejs не является допустимым xml / html. В открывающем и закрывающем тегах есть несоответствия

Ответ №1:

Вам нужно будет передать admins , как:

 res.render('table', {
    admins: [admin]
});