Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
09-06-2020 03:58 AM
Hi all! I have a problem with my neo4j project. Basically I have loaded multiple CSVs and created nodes from them, everything's alright. But now I want to create a relationship between two nodes with some properties, and I want to relate these two nodes with two conditions:
it is a Movie<-[RATED]-User kind of relationship. I have the csv file for movie ratings that contains the user id and movie id columns, so I would like to create this relationship binding ratings(userID) with users(userID) and ratings(movieID) with movies(movieID). I know I'm not so clear, but as in sql where you can join tables on conditions like movie.id = ratings.id, that's what I want to do in neo4j. Hope I've explained the concept.
09-07-2020 09:47 AM
Hello @fed.schiavone and welcome to the Neo4j community
Can you upload the image schema of your database?
CALL db.schema.visualization()
Can you also give us the list of Labels and properties of your database?
Regards,
Cobra
09-08-2020 12:31 AM
Hi!
This is the schema. I've tried to create that relationship on my own, but I don't know if it was good:
:auto USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM
"file:///ratings_table.csv" AS line
MATCH (m:Movie), (u:User)
WHERE m.movieId = toInteger(line.movieId) AND u.userId = toInteger(line.userId)
CREATE (u)-[:RATED {rating: toFloat(line.rating), day: toInteger(line.day), month: toInteger(line.month), year: toInteger(line.year), movieId: toInteger(line.movieId), userId: toInteger(line.userId)}]->(m);
Anyway my labels are:
I've stored the same properties in more than one node for creating the relationships based on the equality of those properties, like you do with foreign keys win relational db.
09-08-2020 12:34 AM
As far as I see, your query looks good. Did you test it?
09-08-2020 12:41 AM
Yes, it works, but I've had to reduce the csv file length (it's a school assignment so I don't really care a lot) because sometimes when I tested that query it went on a loop, I mean it took too long.
09-08-2020 12:54 AM
Did you put UNIQUE CONSTRAINTS on userId, moverId, genreId and tagId? It will speed up the load of nodes and relations
09-08-2020 06:47 AM
I will try! I'll let you know if it works
All the sessions of the conference are now available online