title: Recursive neo4j query
body: <p>I have a graph which has categories and sub-categories and sub-sub-categories to indefinite level.
  How I can I get all this hierarchical data in one cipher query?</p>
  
  <p>I currently have this query :</p>
  
  <pre><code>START category=node:categoryNameIndex(categoryName = "category") 
  MATCH path = category &lt;-        [rel:parentCategory] - subcategory 
  RETURN category, collect(subcategory);
  </code></pre>
  
  <p>Which gives me following result:</p>
  
  <pre><code>| category                                                                                               | collect(subcategory)                                                                                                                                                                                           |
  ==&gt; +-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  ==&gt; | Node[26]{categoryName:"Test2",categoryDescription:"testDesc",imageUrl:"testUrl",imageName:"imageName"} | [Node[25]{categoryName:"Test1",categoryDescription:"testDesc",imageUrl:"testUrl",imageName:"imageName"}]                                                                                                       |
  ==&gt; | 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"}] |
  </code></pre>
  
  <p>I am using node-neo4j.
  I will give an example of what I want in json format. </p>
  
  <pre><code>[{
      "categoryName": "Test2",
      "categoryDescription": "testDesc",
      "imageUrl": "testUrl",
      "children": [{
          "categoryName": "Test1",
          "categoryDescription": "testDesc",
          "imageUrl": "testUrl",
          "children" :  [{
              "categoryName": "Test1",
              "categoryDescription": "testDesc",
              "imageUrl": "testUrl"
          }]
      }]
  }]
  </code></pre>
  
  <p>I this possible? I know I can always do it programmatically OR by using multiple queries. But it will very helpful if it can be done in a single query.</p>