Note that there are some explanatory texts on larger screens.

plurals
  1. PONeo4j aggregate/count of connected nodes
    text
    copied!<p>I'm trying to do a count of nodes connected to node A, where node A is part of a Cypher query starting from node B, and I'm getting unexpected results. Here's an example setup. Pretend we're looking at books and owners, and books cite other books while owners of course own books:</p> <pre><code>Book B1 Book B2 CITES B1 Book B3 CITES B1 Book B4 Owner O1 OWNS B1 Owner O2 OWNS B2 Owner O3 OWNS B3 and B4 </code></pre> <p>So let's say I'm looking at Book B1, and I want to find each book that cites it, then count the books owned by each person who owns the citing book. So if I start with B1, I should find owners O2 and O3, since each owns a book that cites B1. If I count the books they own, I should get 1 for O2, and 2 for O3.</p> <p>So first, a query to just list the owners works fine:</p> <pre><code>start a=node(1) MATCH a&lt;-[:CITES]-b&lt;-[:OWNS]-c return c.name </code></pre> <p>That returns the names as expected. But then this query:</p> <pre><code>start a=node(1) MATCH a&lt;-[:CITES]-b&lt;-[:OWNS]-c-[:OWNS]-&gt;d return c.name, count(d) </code></pre> <p>It seems as though it should get to c, which is the list of owners, then go through the OWNS relationship to the owned books as d, and count them. But instead I get:</p> <pre><code>+--------------------+ | c.name | count(d) | +--------------------+ | "O3" | 1 | +--------------------+ </code></pre> <p>It feels like it's leaving out the books/nodes that have already been found through the other OWNS link -- the ones represented by b. Is there any way to do this in a single query, or is it best to gather up the owners as c, then query again for each of them? It feels like this should be possible, but I haven't figured it out yet. Any ideas would be great -- thanks in advance.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload