I\'ve a query that fetches nodes based on a property
MATCH (c { type: \'sometype\' })
WITH c LIMIT 100
RETURN c
all I want is to also fetch
I guess there are multiple ways to do that. One approach is to find all nodes for the given type and build a collection out of them (cs
). Then match again that group, this time with outgoing relationships to any node and filter that to make sure the endnode is in cs
:
MATCH (c {type:'sometype'})
WITH collect(c) as cs
MATCH (x {type:'sometype'})-[r]->(y)
WHERE y in cs
RETURN startNode(r).name, endNode(r).name
Don't know your graph model, but I think it could be a good idea to refactor the property type='sometype'
into a label sometype
. In this case the query would look like this:
MATCH (c:Group1)
WITH collect(c) as cs
MATCH (x:Group1)-[r]->(y)
WHERE y in cs
RETURN startNode(r).name, endNode(r).name