Can you help me to build cypher query? i have following graph db structure:
(parent:Category)-[:subcategory]->(child:Category)
With this graph data i have hierarchical tree with deep level.
I found following code on Stackoverfllow.com and changed for my data:
MATCH (root:Category)-[:subcategory]->(parent:Category)-[:subcategory]->(child:Category)
WITH root, {category: parent, children: collect(child)} AS parent_with_children
WHERE NOT(()-[:subcategory]->(root))
RETURN {category: root, children: collect(parent_with_children)}
But he is build response only for depth with 3 levels of tree. I need bigger. I'm try to build json response like this example:
[
category: {
name: "PC"
children: {
category: {
name: "Parts"
children: {
category: {
name: "CPU"
...
}
}
},
category: {
name: "Accessories"
...
}
}
},
category: {
name: "Laptop"
...
}
]
The Cypher can make recursive calls? I think this will be better.
Thanks.
P.S. I know there are similar questions on SO, but they did not help me.
See Question&Answers more detail:os