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

220
Vistas
How to declare an array of different types in a Mongoose schema?

I am trying to create a Mongoose schema which contains a field that should be an array that contains different types/objects.

For example:

myArrayField: [
 { type: 'type1', type1Property: 'blabla', type1Property2: 'blabla'},
 { type: 'type2', type2Property2: 'blablo' }
]

I have taken a look at discriminators without any success and I have found mongoose.Schema.Types.Mixed. However, Mixed seems to be very open in terms that Mongo will not check anything about it. I would like to know if I can specify the different types the array can have, something like:

myArrayField: [ SchemaType1, SchemaType2]

So items can follow SchemaType1 OR SchemaType2.

Thank you in advance and regards

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Only one type can be assigned to a field. May be you should create one schema with two fields that has different types and required attributes are set to false which is default.

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