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

225
Visualizações
Skip validation for one field, not all the schema

I have the following long schema:

const mySchema = new mongoose.Schema({
  // some stuff, email, lastName ... etc
  firstName: {
    type: String,
    required: true,
  }
  password: {
    type: String,
    minLength: 8,
    maxLength: 120,
  }
})

And I am inside one of the routes, I want to save a document that I am editing, but I only want to skip one validation, not the entire schema, I want to skip the validation for the firstName field, but I want the rest of the fields to be validated.

Is there something that I can do in Mongoose such as:

userDoc.firstName = "new first name";
const newDoc = await userDoc.save({ validateBeforeSave: yes, but not for firstName })

Is there something like that?

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

0

According to Mongoose documentation, there is a method called $ignore:

Don't run validation on this path or persist changes to this path.

Example:

doc.foo = null;
doc.$ignore('foo');
doc.save(); // changes to foo will not be persisted and validators won't be run
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