I have a chart that has categories and subcategories and sub-sections to an indefinite level. How can I get all this hierarchical data in one encrypted request?
I currently have this query:
START category=node:categoryNameIndex(categoryName = "category") MATCH path = category <- [rel:parentCategory] - subcategory RETURN category, collect(subcategory);
Which gives me the following result:
| category | collect(subcategory) | ==> +-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ ==> | Node[26]{categoryName:"Test2",categoryDescription:"testDesc",imageUrl:"testUrl",imageName:"imageName"} | [Node[25]{categoryName:"Test1",categoryDescription:"testDesc",imageUrl:"testUrl",imageName:"imageName"}] | ==> | Node[1]{categoryName:"Test1",categoryDescription:"testDesc",imageUrl:"testUrl",imageName:"imageName"} | [Node[26]{categoryName:"Test2",categoryDescription:"testDesc",imageUrl:"testUrl",imageName:"imageName"},Node[2]{categoryName:"Test2",categoryDescription:"testDesc",imageUrl:"testUrl",imageName:"imageName"}] |
I am using node -neo4j. I will give an example of what I want in json format.
[{ "categoryName": "Test2", "categoryDescription": "testDesc", "imageUrl": "testUrl", "children": [{ "categoryName": "Test1", "categoryDescription": "testDesc", "imageUrl": "testUrl", "children" : [{ "categoryName": "Test1", "categoryDescription": "testDesc", "imageUrl": "testUrl" }] }] }]
Am I possible? I know that I can always do this programmatically OR using multiple queries. But it will be very useful if it can be done in one request.