问题描述
我有一个neo4j数据库与以下:
I have a neo4j db with the following:
a:Foo
b:Bar
约有10%的db has(a) - [:has] - >(b)
about 10% of db have (a)-[:has]->(b)
我需要只获得没有这种关系的节点!
I need to get only the nodes that do NOT have that relationship!
以前做的() - [r?] - 已经完美!但是它不再支持:(相反,做他们建议一个可选的匹配(a:Foo) - [r:has] - >(b:Bar)WHERE b是NULL返回a匹配需要BOTH节点要么在那里,要么BOTH节点不在那里...
previously doing ()-[r?]-() would've been perfect! however it is no longer supported :( instead, doing as they suggest a "OPTIONAL MATCH (a:Foo)-[r:has]->(b:Bar) WHERE b is NULL RETURN a" gives me a null result since optional match needs BOTH nodes to either be there or BOTH nodes not to be there...
那么如何获得所有的a:Foo到b:Bar?
So how do i get all the "a:Foo" nodes that are NOT attached to "b:Bar"?
注意:数据集是数百万个节点,因此查询需要有效率,否则超时。
Note: dataset is millions of nodes so the query needs to be efficient or otherwise it times out.
谢谢!
推荐答案
这将是
MATCH (a:Foo) WHERE not ((a)-[:has]->(:Bar)) RETURN a;
这篇关于找到没有特定关系的节点(Cypher / neo4j)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!