"No relationship" in cypher request

How is it possible in cypher to have a request such as: "return all people who follow ana who do not follow anyone"?

In the following (where I have the identifier of the beginning of the node clarified after the request), "r is null" - the part does not work:

START o=node({id}) MATCH (a)-[:follows]->(b)-[r]->(c) WHERE a.name="anna" and r is null RETURN b 

Right now, “follows” is the only attitude I have. But also

 START o=node({id}) MATCH (a)-[:follows]->(b)-[:follows]->(c) WHERE a.name="anna" and c is null RETURN b* does not work. 

Doesn't work, I mean: I am not getting any results, although some should be.

+8
neo4j cypher
source share
1 answer

It will not be a match pattern if it does not exist. match is for finding things, not for finding things. You can put such a predicate in the where clause:

 START a=node({id}) MATCH (a)-[:follows]->(b) WHERE not(b-[:follows]->()) RETURN b 
+18
source share

All Articles