Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find Neo4j nodes where the property is not set

Tags:

neo4j

cypher

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?

like image 455
Andrei R Avatar asked Feb 15 '16 02:02

Andrei R


People also ask

Is null in Neo4j?

In Neo4j, since there is no table schema or equivalent to restrict possible properties, non-existence and null are equivalent for node and relationship properties. That is, there really is no such thing as a property with a null value; null indicates that the property doesn't exist at all.

Can u relabel node in Neo4j?

You can change the nodes associated with a label but you can't change the type of a relationship.

What is optional match in Neo4j?

An OPTIONAL MATCH matches patterns against your graph database, just like a MATCH does. The difference is that if no matches are found, OPTIONAL MATCH will use a null for missing parts of the pattern. OPTIONAL MATCH could be considered the Cypher equivalent of the outer join in SQL.


1 Answers

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 
like image 108
manonthemat Avatar answered Sep 16 '22 15:09

manonthemat