user1919
user1919

Reputation: 3938

How to get nodes in neo4j based on property value

I have created some nodes with a property called: color. I haven't assigned any values to this property. Now I want to write a query to get all the nodes which have this property "NULL".

My query is this:

  MATCH (n:Image) WHERE n.color='' RETURN n

But this returns nothing. How can I get all the nodes which belong to the label:Image and have the property:Color empty?

I also tried this with no luck:

MATCH (n:Image) WHERE n.color IS NULL RETURN n

Thanks D.

Upvotes: 1

Views: 3138

Answers (2)

sAguinaga
sAguinaga

Reputation: 659

Here is what worked for me: WHERE not (toString(n.color) = '')

Upvotes: 0

Luanne
Luanne

Reputation: 19373

Null isn't a valid property value- if values are not assigned, or explicitly assigned null, then the property doesn't exist on the node.

You can use either

MATCH (n:Image) where not(has(n.color)) return n

to check if the property exists on the node or simply

MATCH (n:Image) where n.color IS NULL

Based on comments below, an empty String is not the same as a missing property/null value.

Upvotes: 5

Related Questions