'How to query to get n level depth nodes in neo4j
I want to write a query that will fetch the ciphers(nodes) along with its child nodes to the n-level.
e.g. if any child is having 1 child node and that child node is also having a sub child and that sub child node is also having a sub child node and it continues to the n times. then I want to fetch a result like
{
P: {
// parent node info,
child: [
// data
{
a1: {
// data
child: [
{
a2: {
// data
// And so on...
}
}
]
}
},
{
b1: {
// data
child: [
{
b2: {
// data
// And so on...
}
}
]
}
}
]
}
Solution 1:[1]
MATCH(P)-[:child*n]->(C)
RETURN P,C
Will return all the nodes in the 'child' path from node P.
'n' specifies the number of hops between P and C with the child relationship.
MATCH(P)-[:child*]->(C)
RETURN P,C
Will return all the nodes in the 'child' path, irrespective of the number of child relationship hops in-between.
Reference - Specifying varying length paths
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |

