查找没有特定关系的节点 (Cypher/neo4j) [英] Finding nodes that do not have specific relationship (Cypher/neo4j)
问题描述
我有一个具有以下内容的 neo4j 数据库:
I have a neo4j db with the following:
a:Foo
b:Bar
大约 10% 的数据库有 (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?]-()
就完美了!然而,它不再受支持:( 相反,按照他们的建议去做
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...
那么如何获取所有未附加到 b:Bar
的 a:Foo
节点?
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)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!