Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

174
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda