Reputation: 903
I currently have a graph database that has 2 node labels and 1 relationship type.
If i run
MATCH (u)-[r]->(n) return u, n
I can see everything. Some nodes have multiple outgoing relationships. I'd like to filter this view for where nodes have 2 or more outgoing relationships. I tried
MATCH (u)-[r]->(n) with count(r) as c,u,n where c > 1 return u, n
But this gives me no results. I've seen some answers on here that return just a node, but I want the 2 nodes and the relationship shown. Any ideas?
Upvotes: 0
Views: 1117
Reputation: 66989
[EDITED]
This should work:
MATCH (u)-->(n)
WITH u, COLLECT(n) AS ns
WHERE SIZE(ns) > 1
RETURN u, ns
If you specify a set of "grouping keys" with an aggregating function like COLLECT()
(in the above query, u
is the sole grouping key), then the aggregation is performed over that set of keys.
So, in the above query, COLLECT(n)
is collecting al the n
nodes for the same u
node.
Upvotes: 2