I have implemented the angular-ui-tree library to present the folder hierarchy.
The nodes are saved in a MongoDB database, with each node object structured as follows:
{
"node_name" : "Folder 1",
"node_path" : "AAABBB",
"node_id" : 103,
"node_parent_path" : "AAA",
"node_parent_id" : 13,
"template" : "Template 1"
}
The Angular-UI-TREE is populated like this:
data = [
{
"node_name": "Folder 1",
...
"nodes": [
{
"node_name": "Folder 1-1",
...
"nodes": [
{
"node_name": "Folder 1-1-1",
...
"nodes": []
}
]
},
{
"node_name": "Folder 1-2",
...
"nodes": []
}
]
},
{
"node_name": "Folder 2",
...
"nodes": []
}
]
Using this structure, the tree will display folders and subfolders similar to:
Folder 1
|
---> Folder 1-1
|
---> Folder 1-1-1
|
---> Folder 1-2
Folder 2
Given the nodes stored in MongoDB following the specified schema, I aim to populate the DATA array for building the UI tree. What would be the most efficient approach to achieve this?
Alternatively, is there a better way to organize and store these nodes in the database to simplify retrieving the information required to build the tree?