Neo4j:检索所有未引用的节点

时间:2013-05-06 14:46:43

标签: neo4j cypher

我有一个非常简单的数据模型,包含source - [:link] - > target。我想找出所有没有传入链接的节点,例如我的数据模型的“根”。我如何在Cypher中做到这一点?

2 个答案:

答案 0 :(得分:3)

您可以过滤 null

START target=node(*)
MATCH target<-[r?:link]-source
WHERE r is null
RETURN target

有关详细信息,请参阅Cypher where clause documentation

或者,您也可以

START target=node(*)
WHERE not(target<-[:link]-source)
RETURN target

*注意:未经测试

答案 1 :(得分:2)

start n=node(*) 
match n<-[?]-m 
with n, count(m) as c 
where c=0 
return n