在 neo4j 中为数组中的每个元素创建关系

Create relationship foreach elements in array in neo4j

我对 neo4j、密码语言有一些问题...

我有这些类型的节点: 电影

 {
   "overview":"An Amazon princess comes to the world of Man to become 
   the greatest of the female superheroes.",
   "actors":[
     "Gal Gadot",
     "Chris Pine",
     "Connie Nielsen",
     "Robin Wright",
     "Danny Huston"],
  "original_title":"Wonder Woman",
  "runtime":141,
  "title":"Wonder Woman"

}

演员

{
 "birthday":"1985-04-30",
 "place_of_birth":"Rosh Ha'ayin, Israel",
 "popularity":54.444332,
 "name":"Gal Gadot"
},

我会在 Actor 和 Movie 之间创建关系 "ACTED_IN",我会为数组 "actors" 中的每个演员执行此操作。

这是命令:

MATCH (f:Movie), (a:Actors)
FOREACH (n IN f.actors | CREATE (f)-[:ACTED_IN]->(a))   

但我不知道将 "WHERE CONDITION"... actors 数组中的每个元素放在哪里 = Actors.name.

感谢您的帮助。

您不需要 FOREACH 即可。将您的查询更改为:

MATCH (f:Movie)
UNWIND f.actors as names
MATCH (a:Actors {name:names})
CREATE (f)-[:ACTED_IN]->(a) 

即:MATCH 所有电影并使用 UNWIND 将名称列表转换为一系列行。之后,MATCH 名演员并创建电影与匹配演员之间的关系。