As I have learnt from another question it is apparently not possible in Cypher alone to copy a subgraph or to duplicate a chain of nodes. But I need to do this somehow. Therefor I looked for a more hacky approach to do this.
Specifically I need to transform am graph that looks like this:
(A)──>(N1:T1)──>(B)
into a graph that looks like this
(A)──>(N1:T1)──>(B)
│ ^
└───>(N2:T2)────┘
Though the part between A
and B
can be arbitrarily long. What matters is that all nodes of type T1
get converted to type T2
in the copy of the original path (the one with N1
in the example).
So, if I have for example this graph:
MERGE (N1:A)-[:r]->(N2:B)-[:r]->(N3:C)
MERGE (N1)-[:r]->(N4:C)-[:r]->(N5:C)
and a query that looks like this:
MATCH p=(:A)-[*0..]->(:B)-[*0..]->(:C)
RETURN p
and I execute it with graph.cypher.execute(<query>)
then the record returned by execute()
is:
| p
---+----------------------------
1 | (:A)-[:r]->(:B)-[:r]->(:C)
Now I would like to get the IDs of all the nodes. Then I could generate a string with Cypher code that represents the copied path and execute it again with execute()
. And in that string I would use the IDs of nodes in the record to connect to the existing nodes in the database. But I recall that it is somehow not possible either, to target nodes in the database from outside via an ID... or is in fact it possible? Are there any other ways I could go about this? Somebody mentioned the dump
functionality, but the documentation is very lacking on that and I don't quite understand how it is supposed to work. And in addition I am not even sure if it does what I need.