问题
I have nodes with bi-relations(follow)
I am trying to create a query which I want to return all following nodes of a specific node and the following nodes of his following nodes(3 hopes depth)
For example assume those relations:
-> symbols follow
A->B
B->A
B->C
C->B
C->D
D->C
C->E
E->C
I am expecting to get this response if I execute the query on node A
B C D E
I tried this:
MATCH (user:User {name:'roi'})-[:nearby*1..3]->(foaf)
WHERE NOT((user)-[:nearby]->(foaf))
RETURN user, foaf
the problem is that I dont get the node (A) followings only the followings of his followings friends
So I got
C D E
I didnt get B
anyone could help? thanks
回答1:
You don't get B
because your WHERE
pattern filters out any node that is [:NEARBY]
to A
. For that particular relationship it is like saying
MATCH A-[:NEARBY]->B
WHERE NOT(A-[:NEARBY]->B)
Edit
If you want a users' friends and friends of friends to depth three but not the user you can do
MATCH (user:User {name:'roi'})-[:NEARBY*1..3]->f
WHERE f <> user
RETURN f
来源:https://stackoverflow.com/questions/32503350/return-my-friends-and-friends-of-friends-using-neo4js-cypher