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

125
Vistas
Get single array from array of array in mongoose aggregate pipeline

I have a collection like this (That I got from last pipeline condition):

[
{_id:"1","field":[{...obj1},{...obj2}]},
{_id:"2","field":[{...obj3},{...obj1}]},
{_id:"3","field":[{...obj4},{...obj5}]},
{_id:"4","field":[{...obj1},{...obj2}]},
]

I want to add more conditions in the pipeline to get :

[{...obj1},{...obj2},{...obj3},{...obj4},{...obj5}]

The order doesn't matter but I want all the objects from field. I am new to mongo and mongoose, so I don't know which aggregation property will work here.

Please help me, I think it is a simple task but I am unable to do so because of lack of knowledge.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

  • $unwind to deconstruct field array,
  • $replaceRoot to replace field object to root
{ $unwind: "$field" },
{ $replaceRoot: { newRoot: "$field" } }

Playground


For unique object try $group stage after $unwind stage,

  {
    $group: {
      _id: "$field.name",
      field: { $first: "$field" }
    }
  },

Playground

over 4 years ago · Santiago Trujillo 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