Daniel Krizian
Daniel Krizian

Reputation: 4716

Match nodes without labels

How to write a CYPHER query that returns only those nodes that do not have labels attached to them? I tried:

match (n:) return n

Invalid input ')': expected whitespace or a label name (line 1, column 10) "match (n:) return n" ^

Upvotes: 18

Views: 7261

Answers (1)

Nicole White
Nicole White

Reputation: 7790

In Neo4j < 2.3:

MATCH n
WHERE length(labels(n)) = 0
RETURN n

In Neo4j >= 2.3:

MATCH (n)
WHERE size(labels(n)) = 0
RETURN n

Upvotes: 37

Related Questions