Since Neo4j is a schema-free graph database, Cypher has two special operators: ?
and !
.
They are used on properties, and are used to deal with missing values. A comparison on a property that does not exist would normally cause an error. Instead of having to always check if the property exists before comparing its value with something else, the special property operators can be used. The question mark makes the comparison always return true if the property is missing, and the exclamation mark makes the comparator return false.
This predicate will evaluate to true if n.prop
is missing.
WHERE n.prop? = "foo"
This predicate will evaluate to false if n.prop
is missing.
WHERE n.prop! = "foo"
Warning | |
---|---|
Mixing the two in the same comparison will lead to unpredictable results. |
This is really syntactic sugar that expands to this:
WHERE n.prop? = "foo"
⇒ WHERE (not(has(n.prop)) OR n.prop = "foo")
WHERE n.prop! = "foo"
⇒ WHERE (has(n.prop) AND n.prop = "foo")
Copyright © 2013 Neo Technology