Find connectors shared between two nodes

Question from Cypher's boss. I know how to get all friends of someone named Rebecca, and the edges between them:

MATCH (rebecca:Person)-[r*1..10]->(friends:Friend)
RETURN rebecca, friends,
       extract(x IN r | {rel: x, start: startNode(x), end: endNode(x)})

And I know how to get all the friends of someone named Robert, and the edges between them:

MATCH (robert:Person)-[r*1..10]->(friends:Friend)
RETURN robert, friends,
       extract(x IN r | {rel: x, start: startNode(x), end: endNode(x)})

But how can I get all the friends that Robert and Rebecca have with each other? Either by combining these two queries, or if there is an easier way overall.

+4
source share
1 answer

you can use

MATCH (rebecca:Person)-[:FRIEND]->(friends:Friend)<-[:FRIEND]-(robert:Person) 
where rebecca.name = "Rebecca" and robert.name= "Robert"    
RETURN friends
+3
source

Source: https://habr.com/ru/post/1670754/


All Articles