Search code examples
neo4jcypher

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.


Solution

  • 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.