title: How to get path to the root node in Neo4j
body: <p>This is the first time I am playing with neo4j and I would be grateful if you could look at my cypher script. I have simple tree of <code>MyNode</code> which are connected to each other with nodeId. </p>
  
  <p><strong>NodeEntity:</strong></p>
  
  <pre><code>@NodeEntity
  public class MyNode {
  
      @GraphId
      private Long id;
  
      private Long nodeId;
      private int amount;
  
      @Relationship(type="BELONGS_TO", direction = Relationship.OUTGOING)
      private MyNode parent;
  
  }
  </code></pre>
  
  <p>Now I would like to get <strong>all nodes up to the root node and make the sum of the <code>amount</code> field of these nodes</strong>. If I have this tree:</p>
  
  <pre><code>100&lt;-102&lt;-103
  100&lt;-101
  </code></pre>
  
  <p>The query:</p>
  
  <pre><code>MATCH (p:MyNode)-[:BELONGS_TO*]-&gt;(c:MyNode) WHERE c.nodeId = 103 RETURN p.nodeId
  </code></pre>
  
  <p>returns the empty set (awaiting 102, 100), however </p>
  
  <pre><code>MATCH (p:MyNode)-[:BELONGS_TO*]-&gt;(c:MyNode) WHERE c.nodeId = 100 RETURN p.nodeId
  </code></pre>
  
  <p>returns 101, 102, 103, so it works in the opposite direction (lists all children of the node and not the path up, towards the root node).</p>