2
votes

Just started learning about graph databases and can't solve this most likely very easy problem (real-world) - any help would be greatly appreciated.

Problem

Given Node X find Subset Y.

diagram.jpg

Using a Neo4j Cypher Query - Direct Image Link

2
Which docs were you using and what do you feel was missing there? - Michael Hunger

2 Answers

2
votes

The query below returns your 'X' node, and a collection of the other nodes labeled A that are also liked by the same B nodes.

MATCH (a:A)<-[:likes]-(:B)-[:likes]->(otherA:A)
WHERE a.id = 'X'
RETURN a, COLLECT(otherA)

I assume here that you identify your A nodes by an id property. There is no need to explicitly make sure that otherA is never the same as a, since Cypher does that for you automatically (see manual).

0
votes

Solution

MATCH (a {api_id: 182983836})<-[:likes]-(b)-[:likes]->(c) RETURN c