Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
12-17-2019 02:23 AM
I have friend-friend data model which has two relationships between any two friend nodes based on how one friend defines the other friend. For example, User "A" can define user "B" as 'FRIEND' and "B" can define "A" as 'BUDDY'. The problems is, when I try to get the 3rd degree of relationship of user "A", it returns user "B", where as the actual result should be "D" only.
MATCH(a:Users {first_name : "A"}) -[:BUDDY|FRIEND*3] -> (b)
RETURN a,b
OR
MATCH (a)-[]-(b)-[]-(c)-[]-(d)
WHERE a.first_name="A"
RETURN a,d
12-17-2019 04:06 AM
A quick fix for your second query would be:
MATCH (a)-[ ]-(b)-[ ]-(c)-[ ]-(d)
WHERE a.first_name="A" AND NOT b = d
RETURN a,d
However, I don't know if it solves your problem in the long term as you probably want to execute all kinds of queries without having to exclude all possibly wrong nodes.
Maybe for your first query you could get all nodes that are 3 hops away (some first collection of nodes) and then get all nodes that are 0-2 nodes away (a second collection of nodes) and then only return those nodes that are in the first but not in the second collection?
12-17-2019 04:30 AM
The response to this question may help you. It appears because the relationship can be reciprocal you don't need to specify the direction of your relationship which would make your first query. See if the proposed solution from that link helps.
All the sessions of the conference are now available online