简体   繁体   English

查找没有特定关系的节点(Cypher / neo4j)

[英]Finding nodes that do not have specific relationship (Cypher/neo4j)

I have a neo4j db with the following: 我有一个neo4j数据库,具有以下内容:

a:Foo
b:Bar

about 10% of db have (a)-[:has]->(b) 大约10%的db有(a)-[:has]->(b)

I need to get only the nodes that do NOT have that relationship! 我只需要获得那些没有这种关系的节点!

previously doing ()-[r?]-() would've been perfect! 以前做()-[r?]-()会很完美! 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... 给我一个null结果,因为可选匹配需要BOTH节点在那里或BOTH节点不在那里......

So how do i get all the a:Foo nodes that are NOT attached to b:Bar ? 那么我怎么得到所有的a:Foo没有附加到b:Bar a:Foo节点?

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;

如果您正在寻找所有单身人士/孤儿,这也有效:

MATCH (a:Foo) WHERE not ((a)--()) RETURN a;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM