jjrz
jjrz

Reputation: 369

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?

Upvotes: 0

Views: 179

Answers (2)

jose_bacoy
jose_bacoy

Reputation: 12704

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

Upvotes: 0

meistermeier
meistermeier

Reputation: 8262

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.

Upvotes: 1

Related Questions