Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

283
Visualizações
How can I delete a user from my mongoose and node web app?

I have so far got an app where users can register and sign in. I have also implicated a role based system, However I am struggling when it comes to deleting a user. I have looked all over the web but nothing seems to work. I think my delete route is fine, but when I click the delete button nothing happens. I have identified the user id in the url but it doesn't delete. Any help would be much appreciated.

in routes/admin.js

//Delete a user
router.delete('/delete/:id', (req, res, next) => {
  try {
    User.findByIdAndDelete({_id: req.params.id});
  // res.redirect('/admin');
  } catch (error) {
    res.redirect('/index');
  }
});

in views/manage-users.ejs

<form action="/admin/delete/:<%= user.id %>" method="delete">
          <button type="submit">DELETE</button>
      </form>
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can do like this.

router.delete("/delete/:id",  (req: Request, res: Response) => {
      const id = req.params.id;
    
    
      Links.deleteOne({ _id: id })
        .then((data) =>
          res.json({
            data: data,
          })
        )
        .catch((error) => {
          return res.send(error);
        });
    });
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda