查找没有特定关系的节点 (Cypher/neo4j) [英] Finding nodes that do not have specific relationship (Cypher/neo4j)

查看:147
本文介绍了查找没有特定关系的节点 (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:Bara: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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆