I have community nodes (c: Community) and user nodes (u:user)
I want to create for each community node one relationship with usernode that is associated with another usernode which is connected with the community node that alredy in database
where (c4: Community) is community that alredy in database and <- [: MEMBER_OF] - (u5: user) - [] - (u6: user) - [: MEMBER_OF] -> (c5: Community) new nodes and relationships
If I understand correctly, this is what you are looking for.
//Assuming c4 already exist in the db......
MATCH (c4:Community {id: 1})
WITH c4
//New entries.......
MERGE (c5:Community {id: 2})
MERGE (u5:User {name:"u5"})
MERGE (u6:User {name:"u6"})
//Connect the users to their respective community........
MERGE (u5)-[:MEMBER_OF]->(c4)
MERGE (u6)-[:MEMBER_OF]->(c5)
//Guessing the relationship type between the users.....
MERGE (u5)-[:FRIEND_OF]->(u6)
RETURN c4, c5, u5, u6
You need to add the id value to the Community node in the FOREACH loop
FOREACH (id IN ids |
MERGE (c5:Community {id: id})
MERGE (u5:user {name:"u5"})
MERGE (u6:user {name:"u6"})
MERGE (u5)-[:MEMBER_OF]->(c)
MERGE (u6)-[:MEMBER_OF]->(c5)
MERGE (u5)-[:FRIEND_OF]->(u6)
)
It depends on the source of User node properties. Just like the Community ids, there should be a mechanism to loop through the User node properties to create new user nodes.