I have a collection which has a parent field that refers to documents from the same collection, now what I do is call them and find the id
of the parent and create a children field where all the subdocuments go, this I do in the controller with an order and I do not know how to make the Database, I think it could be with a mapReduce
but I'm not sure how it is done.
My collection looks like this:
0:{
id:1,
nombre:'pepito perez'
},
1:{
id:2,
nombre:'jony se',
padre:1
},
2:{
id:3,
nombre:'rojas del totaso'
},
3:{
id:4,
nombre:'rosa melano'
padre:3
}
What I want to achieve is the following:
0:{
id:1,
nombre:'pepito perez'
hijos:[
{
id:2,
nombre:'jony se',
padre:1
}
]
},
1:{
id:3,
nombre:'rojas del totaso',
hijjos:[
{
id:4,
nombre:'rosa melano'
padre:3
}
]
}
Thank you in advance