2
votes

I have a neo4j database with some data in it. Most of the nodes have a name property, but not all of them; I'd like to construct a Cypher query to match and return all those that don't.

I've tried all the following, but all of them give 0 results:

MATCH (n { name: NULL }) RETURN n
MATCH (n { name: null }) RETURN n
MATCH (n) WHERE n.name = NULL RETURN n
MATCH (n) WHERE n.name = null RETURN n

However, I have at least one node with no name property specified, which I can prove either through

MATCH (n) WHERE id(n) = 4 RETURN n

and examining the node in the results view, or by noting that

MATCH (n) WHERE id(n) = 4 RETURN n.name

returns null.

How do I match all the nodes that don't have a name property?

2

2 Answers

4
votes

There is the HAS function:

MATCH (n) WHERE not has(n.name) RETURN n
6
votes

EXISTS() has replaced HAS() so your query would now look like:

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

https://neo4j.com/docs/cypher-refcard/current/