gooneraki
gooneraki

Reputation: 81

How do you use apoc.refactor.cloneSubgraph to clone a graph in neo4j

I couldn't find a documentation or an example anywhere.

I created a graph and added the property

example:1

in all my nodes.

Now I want to make an exact copy of this graph with the only difference of making this property equal to 2

example:2

Thanks

Upvotes: 1

Views: 345

Answers (1)

Francois Vanderseypen
Francois Vanderseypen

Reputation: 1521

First, you need to define how to fetch this sub-graph. Assuming it's a star-graph identified by a central node with name 'center' you would use something like this:

Match path=(s{name: 'center')-->(n)
With collect(path) as paths
Call apoc.refactor.cloneSubgraphFromPaths(paths)
Yield input, output
With output
Set output.example = 2
Return output

The With clause can be used multiple times to alter the cloned graph. If your initial graph is not a star-shaped graph you simply need to change the first 'Match' clause corresponding to your case.

Upvotes: 1

Related Questions