When should I use the aggregation pipeline?
Scenerio: I have some mongo db documents like this
`
{
id:"",
text:"",
dept:"",
group:"",
parent:"",
}
`
Now I need to prepare a tree structure out of it using the parent field.
`
tree:[
{
id:"",
text:"",
dept:"",
group:"",
parent:"",
children:[
{
id:"",
text:"",
dept:"",
group:"",
parent:"",
}]
},{
id:"",
text:"",
dept:"",
group:"",
parent:"",
}]
`
Now this structure could be heavily nested. As much of my knowledge I can write a aggregation pipeline for making this structure. but the question is this structure will be prepared frequently like on each refresh of the page. Should we use the pipeline or we should store the json documents in the tree structure as it is.