【发布时间】:2013-11-23 22:10:25
【问题描述】:
在使用 neo4j-shell 的 Neo4j Cypher 中,我可以基于如下属性与单个节点建立关系:
match (p:Taxon{taxId:'9605'}),(t:Taxon{parentTaxId:p.taxId})
create unique (p)-[:PARENT_OF]->(t);
在 p 中设置 taxId 后,它按预期运行,并根据需要创建关系。但是,当我尝试通过将查询更改为将其应用于所有节点时:
match (p:Taxon),(t:Taxon{parentTaxId:p.taxId})
create unique (p)-[:PARENT_OF]->(t);
我收到一个错误:
NotFoundException:未知标识符
t。
我不明白为什么 t 现在无效。我错过了什么明显的东西吗?
【问题讨论】:
-
啊,我明白发生了什么。第二个查询不起作用,因为有没有孩子的分类群。在这种情况下,找不到 t,因此没有要创建关系的 t。是否可以在 where 子句中添加一些东西来检测是否找不到 t?
-
类似:匹配 (p:Taxon),(t:Taxon{parentTaxId:p.taxId}) where not(t is null) 创建唯一 (p)-[:PARENT_OF]->( t);
-
也试过:\match (t:Taxon),(p:Taxon{taxId:t.parentTaxId}) where HAS(t.parentTaxId) create unique (p)-[:PARENT_OF]-> (t);