'Filtering on pattern using NOT deprecated
When I write a cypher query with Filter on patterns using NOT, the Neo4j browser shows the following warning:
This feature is deprecated and will be removed in future versions.
Coercion of list to boolean is deprecated. Please consider using `NOT isEmpty(...)` instead.
My query is:
MATCH (a)-->(b)
WHERE NOT (b)-->(a)
RETURN a, b
Is there a better way to write this query, so it works in future Neo4j version?
Solution 1:[1]
You could be using NOT exists().
For a given
CREATE (b:User{name:'B'})-[:ANY]->(:User{name:'A'})-[:ANY]->(b)<-[:ANY]-(:User{name:'C'})
Your query returns:
???????????????????????????
?"a" ?"b" ?
???????????????????????????
?{"name":"C"}?{"name":"B"}?
???????????????????????????
If you use
MATCH (a)-->(b)
WHERE NOT exists((b)-->(a))
RETURN a, b
It also returns
???????????????????????????
?"a" ?"b" ?
???????????????????????????
?{"name":"C"}?{"name":"B"}?
???????????????????????????
but uses the exists(Pattern) clause that is not deprecated.
Solution 2:[2]
Both isEmpty() and exists() function/predicate will work.
MATCH (a)-->(b)
WHERE NOT IsEmpty((b)-->(a))
RETURN a, b
OR
MATCH (a)-->(b)
WHERE NOT exists((b)-->(a))
RETURN a, b
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | meistermeier |
| Solution 2 | jose_bacoy |
