Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
11-16-2020 12:17 PM
Hi, everybody,
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
i want to get something like
(c4: Community) <- [: MEMBER_OF] - (u5: user) - [] - (u6: user) - [: MEMBER_OF] -> (c5: Community)
where (c4: Community) is community that alredy in database and <- [: MEMBER_OF] - (u5: user) - [] - (u6: user) - [: MEMBER_OF] -> (c5: Community)
new nodes and relationships
Thanks for your attention and answers
11-16-2020 02:01 PM
Hello @yevheniy.derykot
So you want to create nodes u5, u6 and c5 and all relationships? Do you have properties to create them?
Regards,
Cobra
11-17-2020 01:28 AM
Yes ids of communities. I think that first I need to collect the ids of community nodes.
11-16-2020 10:58 PM
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
11-17-2020 01:33 AM
Yes, this is very close to what I want to do
i tried this code and it didn't work
MATCH (c:Community)
WITH collect(DISTINCT c.id) AS ids
return ids
FOREACH (id IN ids |
MERGE (c5:Community)
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)
)
11-17-2020 09:16 AM
Move this, 'return ids' to the bottom (after FOREACH loop).
11-17-2020 07:28 PM
Thanks for the advice
this is what happened
but I wanted each blue node (community node) to have a separate connection as in the picture below
11-17-2020 07:41 PM
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)
)
11-17-2020 08:05 PM
got the same results.
I think the problem is in this line
MERGE (u5)-[:MEMBER_OF]->(c)
11-17-2020 11:05 PM
Yes. Correct the WITH statement:
MATCH (c:Community)
WITH collect(DISTINCT c.id) AS ids, c
11-18-2020 12:09 PM
Thanks for the help
That's what i get and this is not what I need
Now there are 7 community nodes in the database, so I need to create 7 new community nodes and 14 new user nodes
11-18-2020 01:18 PM
In your FOREACH loop you have only two user nodes:
MERGE (u5:user {name:"u5"})
MERGE (u6:user {name:"u6"})
11-18-2020 04:09 PM
yes, I see but how to automatically create the required number of links and nodes ?
11-18-2020 06:40 PM
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.
All the sessions of the conference are now available online