Neo4j 1.9 Cypher Issue with "Has" Clause

1 neo4j nosql cypher

I'm migrating to Neo4j 1.9 and updating the cypher queries according to the deprecations migration guide, specifically:

The ! property operator in Cypher Expressions like node.property! = "value" have been deprecated, please use has(node.property) AND node.property = "value" instead.

The problem is that when using the HAS clause in combination with NOT I can't get the expected result. For example:

When the status property exists and is set to something other than "DONE":

AND not(n.status! = "DONE") 
Run Code Online (Sandbox Code Playgroud)

evaluates true (as expected)

AND not(has(n.status) AND n.status = "DONE")
Run Code Online (Sandbox Code Playgroud)

evaluates false???

When the status property doesn't exist

AND not(n.status! = "DONE") 
Run Code Online (Sandbox Code Playgroud)

evaluates false

AND not(has(n.status) AND n.status = "DONE")
Run Code Online (Sandbox Code Playgroud)

throws exception because the node doesn't exist, surely HAS should have prevented this? It's as though wrapping the check in NOT prevents the HAS check from being executed.

This can be reproduced via the live query examples on the neo4j docs website using the following queries:

MATCH n 
WHERE NOT (n.name! = 'Peter') 
RETURN n
Run Code Online (Sandbox Code Playgroud)

This returns all (3) nodes who either have no name or whose name is not "Peter". This is the result I want to reproduce but without using the now deprecated "!" operator.

MATCH n 
WHERE NOT (HAS (n.name) AND n.name = 'Peter') 
RETURN n
Run Code Online (Sandbox Code Playgroud)

Throws a node not found exception because one node doesn't have a name property. :/

MATCH n 
WHERE (HAS (n.name) AND n.name = 'Peter') 
RETURN n
Run Code Online (Sandbox Code Playgroud)

Correctly returns the node whose name is "Peter".

我尝试用几种替代方法重写查询,但似乎无法可靠地获得我想要的结果与已弃用的匹配!运营商.也许它只是迟到了,我错过了一些明显的东西?:)

任何帮助表示赞赏!

谢谢,马克.

Tho*_*nzl 6

我认为引发异常的第二个查询是一个错误.

你可以做的是使用de Morgan定律来改变谓词:

MATCH n 
WHERE NOT (HAS (n.name)) OR (n.name <> 'Peter') 
RETURN n
Run Code Online (Sandbox Code Playgroud)