Reputation: 1
match (a)-[r:friend_of]-(b) where a.name='john' return b.name
in this case it will giving all the nodes which are [r:friend_of]
relation with john,
but, I want those who are not [r:friend_of]
relation with john
so, can any plz help me, thanks in advance,
match (a)- NOT [r:friend_of]-(b) where a.name='john' return b.name
match (a)- <> [r:friend_of]-(b) where a.name='john' return b.name
am trying this, but am not getting
Upvotes: 0
Views: 474
Reputation: 66999
Cypher does not have a special syntax for finding "unrelated" nodes.
Here is one way to find people who are not friends with John:
MATCH (john:Person {name:'John'})-[:friend_of]-(f:Person)
WITH john, COLLECT(f) AS friends
MATCH (notFriend:Person)
WHERE NOT notFriend IN friends
RETURN notFriend
This query first gets a list of all the friends of John, and then returns the people who are not in that list.
Upvotes: 2
Reputation: 344
I'm reading your question as, Find all nodes that are related to nodes that have a name property value of "john" and that are not related by a "friend_of" relationship. If that's correct then I think this will do what you're looking for:
MATCH (a)-[r]-(b) WHERE TYPE(r) <> "friend_of" AND a.name = 'john' RETURN b.name
Upvotes: 0