Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

315
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!