在Neo4j的

问题描述:

我有一些问题的Neo4j,CYPHER语言创建数组关系的foreach元素...在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(演员)之间创建一个关系“ACTED_IN” nd电影,我会为阵列中的每个演员“演员”这样做。

这是命令:

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

,但我不知道在哪里放置“WHERE条件” ......在演员阵= Actors.name每个元素。

谢谢你的帮助。

你不需要FOREACH来做到这一点。您的查询更改为:

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

那就是:MATCH所有电影和使用UNWIND到名称列表转换成排的序列。之后,MATCH演员按名称创建电影和匹配演员之间的关系。

+0

谢谢你队友! – randy192

+0

不客气! –