Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
11-17-2021 04:56 PM
Hello,
Using Cypher language only, based on a liste of strings e.g [ "A", "B", "C" ], I want to create the following path:
( n1:Test {ps: "A"}) -[:NEXT]-> (n2:Test {ps: "B"}) -[:NEXT]-> (n3:Test {ps:"C"})
The list would be of any length. Nodes and relationships can already exist in the graph, hence reusing them, creating only connecting relationships and / or nodes when required.
11-19-2021 05:39 AM
You could do something like this:
WITH [ "A", "B", "C" ] as list
UNWIND range(0, size(list) - 1) as index // list from 0 to size-1, so [0,1,2]
MERGE (n:Test {ps: list[index]})
WITH n, index, list
WHERE index > 0 // to exclude first item from rel creation
MATCH (m:Test {ps: list[index -1]})
MERGE p=(m)-[:NEXT]->(n)
RETURN p
All the sessions of the conference are now available online