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

207
Visualizações
In Mongoose, what would I use .pre() middleware function for?

I am just wondering what mongoose .pre('validate') and .pre('save') would be used for. I know how it works and what it does, but I am not sure what situation I could have that I would use it for. Couldn't I just do everything I need within code? And what is difference between validate and save?

Sorry if these are dumb questions, I've done my research but not sure when to use these features

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

We use the .pre() function that is executed before or after a certain action that you specify. When you want to run a function every time before you save a document in the DB, we would you a pre-hook for that.

Example : Before saving a user to the database, you could call a function that would log the user into to a logging service.

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