In the following distinct coActor query, why do we not see "Tom Hanks" as one of the coActors. The way I understand this query, we are matching all the movies Tom Hanks acted and then getting all the actors who were part of those movies. What am I missing here?
MATCH (tom:Person {name:"Tom Hanks"})-[:ACTED_IN]->(m)<-[:ACTED_IN]-(coActors) RETURN DISTINCT coActors.name
It is because in a cypher query, the transversal will not traverse the same relationship twice in the same match.
You should get Tom Hanks if you write the query like this:
MATCH (tom:Person {name:"Tom Hanks"})-[:ACTED_IN]->(m)
MATCH (m)<-[:ACTED_IN]-(coActors) RETURN DISTINCT coActors.name
In this scenario, I would think the first result is more appropriate, as coactor to me implies actors other than Tom Hanks.