Hello everyone . This is my first time trying to deal with this kind of problem on Neo4j and I could use some help either with syntax, how to face the problem or both.
What I'm looking as result is something like this:
What I'v tried to start is importing nodes like this
LOAD CSV FROM 'file:///test.csv' AS line
CREATE (:Member { id: line[0], invitedBy: line[2]})
but as soon as I checked, noticed that nodes were duplicated. So I started investigating MERGE.
I thought I should have lists (arrays) because one Member could had been invited by many people as soon as it was into different workspaces. Then I tried to use some kind of map or dictionary but I'm not finding the way.
Based on what you are trying to accomplish, you might want to think about it differently.
Here is another way to approach it.
Create a User node for all of the users in your data set. Don't separate your Users by InvitedBy node property.
Create a Workspace node for all of the workspaces in your data set.
Use two relationships in your graph. INVITED_BY and BELONGS_TO.
So your graph schema will look something like this.
If you are interested, here are the Cypher scripts that should provide you what you are looking for, or at least provide another perspective.
// Create the User nodes
LOAD CSV WITH HEADERS FROM 'file:///test.csv' AS line
MERGE (m:Member { id: line.user})
;
// Create the Workspace nodes
LOAD CSV WITH HEADERS FROM 'file:///test.csv' AS line
MERGE (w:Workspace { id: line.workspace})
;
// Create the relationships
LOAD CSV WITH HEADERS FROM 'file:///test.csv' AS line
MATCH (m1:Member { id: line.user})
MATCH (m2:Member { id: line.invitedBy})
MATCH (w:Workspace { id: line.workspace})
MERGE (m1)-[:BELONGS_TO]->(w)
MERGE (m1)-[:INVITED_BY]->(m2)
;