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

310
Vistas
How to get a subdocument with a populate in mongoose

I configuring an api similar to the blog category.

The object ID of the category is recorded for each post.

Please help us with how we can extract data in the form of the third image.

  • first code: category data
  • second code : post data ( category object id value )
  • third code : the result that I want

{ // category
    _id: '61dd8eb5368930c3a6cee140',
    name: 'parent',
    childern: [
        { _id: '61dd8eb5368930c3a6cee141',
          name: 'child1' },
        { _id: '61dd8eb5368930c3a6cee142',
          name: 'child2' }
    ]
}

first code


{ // post data
    _id: '61dd8eb5368930c3a6cee160',
    name: 'first post - parent',
    category: '61dd8eb5368930c3a6cee140',
},
{
    _id: '61dd8eb5368930c3a6cee161',
    name: 'second post - child',
    category: '61dd8eb5368930c3a6cee141',
},

second code


{ // the result that I want
    _id: '61dd8eb5368930c3a6cee160',
    name: 'first post - parent',
    category: {
        _id: '61dd8eb5368930c3a6cee140',
        name: 'parent'
    }
},
{
    _id: '61dd8eb5368930c3a6cee161',
    name: 'second post - child',
    category: {
        _id: '61dd8eb5368930c3a6cee141',
        name: 'child1'
    }
},

third code == i want it

pleas help me

about 4 years ago · Juan Pablo Isaza
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