cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Neo4j create a relationship with nodes with the same id problem

gusto
Node Link

I have two different types of nodes that I load from a dataset. these nodes have the same id values ​​with different names. how can i relate between them using these same id values. I tried the following two separate codes, but there is no change. can you help?

match (movie:Movie {id:movie.movieId}), (movieGenres:MovieGenres {id:movieGenres.movieGenresId}) 
create (movie) - [:GENRE] -> (movieGenres)

match (movie:Movie where id(movie)=toInteger(movie.movieId))
match (movieGenres:MovieGenres where id(movieGenres)=toInteger(movieGenres.movieGenresId) )
merge (movie) - [:GENRE] -> (movieGenres)

 

1 ACCEPTED SOLUTION

This query should work normally

 

MATCH (m:Movie) 
MATCH (g:MovieGenres) 
WHERE toInteger(m.movieId) = toInteger(g.moviesGenresId) 
MERGE (m)-[:GENRE]->(g)

 

View solution in original post

9 REPLIES 9

Cobra
Ninja
Ninja

Hello @gusto 😊

The id() function returns the Neo4j internal ID of node/relationship.

This query should do what you want:

 

MATCH (m:Movie) 
MATCH (g:MovieGenres) 
WHERE m.movieId = g.movieGenresId 
MERGE (m)-[:GENRE]->(g)

 

Regards,
Cobra

gusto
Node Link

hi @Cobra cobra, thanks for your reply.
But when I try with the code you showed, there is no change.
I want to connect different nodes with same id's.
thanks again.

Neo4j Internal ID are unique so it won't be possible by definition. Do you have common ids between Movie and MovieGenres nodes?

Can you tell me all the properties you have for these two nodes and the type of this properties?

Can you share some queries to recreate your dataset?

gusto
Node Link

Screenshot 2022-08-03 142811.pngScreenshot 2022-08-03 142927.png
As seen in the picture, movieID and moviesGenresId have the same value. I wanted to associate nodes using them. I don't know if such a thing is possible. is it possible? thanks.

This query should work normally

 

MATCH (m:Movie) 
MATCH (g:MovieGenres) 
WHERE toInteger(m.movieId) = toInteger(g.moviesGenresId) 
MERGE (m)-[:GENRE]->(g)

 

There was a typo in my query, the s was messing in moviesGenresId. You can try to also remove toInteger() functions.

gusto
Node Link

Thank you very much it worked. I have one more problem. I have two separate node types movies_genres and directors_genres. but in one the name is visible on the nodes while the other is not. why could it be?

I guess you are looking for this.