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

180
Visualizações
How to add an array of a specific length using mongoose.Schema in Node.js?

I'm working on a project and need an array value, when entered, to have an array length of at least 12. I've read through some of the documentation on their site and I haven't found anything yet so I thought it wouldn't hurt to post here while I continue searching.

This is an example of the code.

const schema = new mongoose.Schema({
Array: {
         type: Array,
         required: true,
       }
});

Any insights you have would be greatly appreciated! If there's something I could clarify better please let me know!

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

0

You can use validate() from mongoose while defining your schema.

const schema = new mongoose.Schema({
Array: {
         type: Array,
         required: true,
         validate : lengthMin12
       }
});


const lengthMin12 = (val) => {
return val.length >= 12;
}

PS : The above link is from the latest version, but validate is available for older mongoose versions too.

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