31
votes

Using Cypher, how can I find a node where a property doesn't exist?

For example, I have two nodes:

A = {foo: true, name: 'A'},  B = { name: 'B'}

Now I'd like to find B, selecting it on the basis of not having the foo property set. How can I do this?

2

2 Answers

60
votes

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
0
votes
MATCH (f) WHERE f.foo IS NULL RETURN f