在 Neo4j 中基于数组值创建关系 [英] Creating relationships based on array values in Neo4j

查看:60
本文介绍了在 Neo4j 中基于数组值创建关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个节点代表两个人:

I have two nodes representing two people:

(:Person {name:"John Smith"})
(:Person {name:"Jane Doe"})

然后我有第三个节点代表这两个人合着的一篇文章:

Then I have a third node representing an article coauthored by these two people:

(:Article {title:"Some_article"}, {Coauthor:["John Smith", "Jane Doe"]})

我的问题是:我可以根据名称匹配在这些节点之间创建关系吗?像这样:

My question is: Can I create a relationship between these nodes based on matching the names? Something like this:

MATCH (n1:Person {name:"Jane Doe"})
MATCH (n2:Article{Coauthor:"Jane Doe"})
CREATE (n2)-[:AUTHORED_BY]->(n1)

这是可能的还是我需要将数组分解为单独的节点属性,例如Coauthor_1、Coauthor_2 等?

Is this possible or do I need to break up the array into separate node properties e.g. Coauthor_1, Coauthor_2 etc?

谢谢

Windows 10 上的 Neo4j CE 3.0.1

Neo4j CE 3.0.1 on Windows 10

推荐答案

您可以使用循环来创建作者关系:

You can use a loop for creating authorship relationships :

MATCH (a:Article {title:"some title"})
UNWIND a.Coauthor as author
MERGE (p:Person {name: author})
MERGE (a)-[:AUTHORED_BY]->(p)

这篇关于在 Neo4j 中基于数组值创建关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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