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.
{ // category
_id: '61dd8eb5368930c3a6cee140',
name: 'parent',
childern: [
{ _id: '61dd8eb5368930c3a6cee141',
name: 'child1' },
{ _id: '61dd8eb5368930c3a6cee142',
name: 'child2' }
]
}
{ // post data
_id: '61dd8eb5368930c3a6cee160',
name: 'first post - parent',
category: '61dd8eb5368930c3a6cee140',
},
{
_id: '61dd8eb5368930c3a6cee161',
name: 'second post - child',
category: '61dd8eb5368930c3a6cee141',
},
{ // 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