如何在 Neo4j 循环中创建关系和 merge/create 新节点

how to create relationship and merge/create new node in loop in neo4j

我正在尝试为列表中的所有 ID 创建朋友关系,但出现错误:

y already declared (line 2, column 41 (offset: 64))

"Merge (y:User{id:"21",name:"b"})
 Merge (y:User{id:"41",name:"d"})
 Merge (y:User{id:"51",name:"e"}) "
                                         ^
 Neo.ClientError.Statement.InvalidSyntax

我正在尝试同时创建一个具有 ID、名称、年份以及与现有节点的关系的新用户。我该怎么做?还有其他方法吗?我非常感谢您的帮助。

MATCH (u:User {id:"2"})
Merge (y:User{id:"21",name:"b",year:"2010"})
Merge (y:User{id:"41",name:"d",year:"2011"})
Merge (y:User{id:"51",name:"e",,year:"2013"}) 
MERGE (u)-[:FRIEND]->(y)

重复使用标识符 y 无效。

尝试

MATCH (u:User {id:"2"})
unwind [{id:"21",name:"b",year:"2010"},
        {id:"41",name:"d",year:"2011"},
        {id:"51",name:"e",year:"2013"}] as user
merge (y:User {id: user.id, name: user.name,year:user.year})
MERGE (u)-[:FRIEND]->(y)