In Neo4j 2.x, it is easy to find all nodes with a certain value for a given property using Cypher 2.0, like so:
MATCH (node {property: 'value'})
RETURN node;
However, how would I find all nodes with any value for property
except for "value"
? I tried using the NOT
operator like so, but this simply returns a syntax error:
MATCH (node {property: NOT 'value'})
RETURN node;
The MATCH clause allows you to specify the patterns Neo4j will search for in the database. This is the primary way of getting data into the current set of bindings. It is worth reading up more on the specification of the patterns themselves in Patterns.
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.
Relationships always has a direction (one direction). Relationships must have a type (one type) to define (classify) what type of relationship they are. Nodes and relationships can have properties (key-value pairs), which further describe them.
The concise syntax for properties in the MATCH clause only works with exact matches.
If you want to do any other kind of match condition, you should the WHERE clause:
MATCH (node)
WHERE node.property <> 'value'
RETURN node;
Another example:
MATCH (node)
WHERE NOT node.property IN ["red", "blue", "yellow"]
RETURN node;
Please note this will do an entire graph scan, which is strongly discouraged. On any reasonable dataset size, this query might not complete or at least not in a timely fashion.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With