Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
07-09-2021 01:24 PM
I'm trying to associate two lists, in a one-to-one relationship.
This query is returning the following: all objects in p are merged with only the first element of r.
I need something like id1(n)-[:HAS_ID]-id2(n)
MATCH p=(n:ID1)
MATCH r=(o:ID2)
WITH p, r LIMIT 100
UNWIND nodes(p) AS ids1
UNWIND nodes(r) AS ids2
MERGE (ids1)-[:HAS_ID]->(ids2)
Solved! Go to Solution.
07-09-2021 02:01 PM
MATCH (a:ID1)
WITH a LIMIT 100
WITH collect(a) AS ids1
MATCH (b:ID2)
WITH ids1, b LIMIT 100
WITH ids1, collect(b) AS ids2
UNWIND range(0, size(ids1)-1) AS i
WITH ids1[i] AS n, ids2[i] AS m
MERGE (n)-[:HAS_ID]->(m)
07-09-2021 01:46 PM
Hello @andreperez
MATCH (a:ID1)
WITH a LIMIT 100
WITH collect(a) AS ids1
MATCH (b:ID2)
WITH ids1, b LIMIT 100
WITH ids1, collect(b) AS ids2
UNWIND range(0, size(ids1)) AS i
MERGE (ids1[i])-[:HAS_ID]->(ids2[i])
Regards,
Cobra
07-09-2021 01:55 PM
Your query makes total sense to me, but Neo4J is complaining 😧
Invalid input 'ids1': expected "(", "allShortestPaths" or "shortestPath" (line 8, column 8 (offset: 175))
"MERGE (ids1[i])-[:HAS_ID]->(ids2[i])"
^
07-09-2021 02:01 PM
MATCH (a:ID1)
WITH a LIMIT 100
WITH collect(a) AS ids1
MATCH (b:ID2)
WITH ids1, b LIMIT 100
WITH ids1, collect(b) AS ids2
UNWIND range(0, size(ids1)-1) AS i
WITH ids1[i] AS n, ids2[i] AS m
MERGE (n)-[:HAS_ID]->(m)
07-09-2021 02:08 PM
Thank you, works perfectly
All the sessions of the conference are now available online