【问题标题】:Create relationship foreach elements in array in neo4j在neo4j的数组中创建关系foreach元素
【发布时间】:2017-06-25 12:44:12
【问题描述】:

我对 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”中的每个 Actor 执行此操作。

这是命令:

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

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

感谢您的帮助。

【问题讨论】:

    标签: neo4j cypher graph-databases


    【解决方案1】:

    您不需要FOREACH 来执行此操作。将您的查询更改为:

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

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

    【讨论】:

    • 这是正确的吗?我将其解读为“在这些演员 ACTED_IN 的电影之间建立关系”。
    猜你喜欢
    • 1970-01-01
    • 2016-06-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多