Find neo4j nodes where property is not set

2019-06-15 00:42发布

问题:

What's a cypher query to find a node where a property doesn't exist? 2 nodes: A = {foo: true, name: 'A'}, B = { name: 'B'}

need to find B because it doesn't have foo, i.e. B.foo is not set

回答1:

As Michael Hunger mentioned

MATCH (n) WHERE NOT EXISTS(n.foo) RETURN n

On older versions of Neo4j you can use HAS:

# Causes error with later versions of Neo4j
MATCH (n) WHERE NOT HAS(n.foo) RETURN n


回答2:

MATCH (f) WHERE f.foo IS NULL RETURN f


标签: neo4j cypher