dbzuk
dbzuk

Reputation: 255

Return paths to nodes with more than N relationships

I have User and Repository nodes in my database, and there are relationships between them.

I want to get back the paths between Users and "Repositories that have more than 100 Users pointing to them" (with a variable number of nodes in between them).

This query works but only returns the Repositories:

match p=(u:User)-[*..2]->(r:Repository)
with *, relationships(p) as rel
with r, count(rel) as rel_count
where rel_count > 100
return r

I also want the Users and paths returned, so I tried this:

match p=(u:User)-[*..2]->(r:Repository)
with *, relationships(p) as rel
with p,r, count(rel) as rel_count
where rel_count > 100
return p

which returns 0 records (versus ~200 for the above query), for reasons I'm uncertain of.

How can I return all the paths to nodes that have more than N relations?

Upvotes: 0

Views: 34

Answers (1)

Graphileon
Graphileon

Reputation: 5385

I would try something like this

MATCH p=(u:User)-[*..2]->(r:Repository)
WITH r,
     COLLECT(p) AS ps,
     COUNT(DISTINCT u) AS userCount
WHERE userCount > 100
UNWIND ps AS p
RETURN p

Upvotes: 1

Related Questions