I intended to clone a single node and its 3 connections, but ended up with multiple clones.
By first MATCHing the entire graph of primary node and related nodes, when I call apoc.refactor.cloneNodes, it seems to iterate over each related node instead of just the primary node I want to clone. Result is the original primary node and 3 clones (instead of the intended 1 clone) connected to the expected related nodes.
. . .
I created this toy graph:
create (a:Node {description:"Spider Man Series"})
create (b:Node {description:"Spidey"})
create (c:Node {description:"Doc Oc"})
create (d:Node {description:"Venom"})
create (a)-[:BELONGS]->(b)
create (a)-[:BELONGS]->(c)
create (a)-[:BELONGS]->(d)
return a,b,c,d
I want to clone "Spider Man Series" (and its relationships):
match (a)-[c]-(b)
where a.description="Spider Man Series"
call apoc.refactor.cloneNodes([a],true) yield output
return a,b,c, output
But this creates 3 clones (one for each related character node). I'm guessing it has to do something with the MATCH having a relationship.
Because if I just limit my MATCH with no relationships, I get the proper clone behavior (the original "Spider Man Series" and the clone "Spider Man Series" with cloned relationships). I'm confused because there's only 1 node that results from the WHERE clause which is stored in (a).
match (a)
where a.description="Spider Man Series"
call apoc.refactor.cloneNodes([a],true) yield output
return a,output
. . .
I tried limiting the related nodes to 2 instead of everything "Spider Man Series" was connected to, but this ALSO gave me a clone for each related node:
match (a)-[c]-(b)
where a.description="Spider Man Series" and b.description in ['Spidey','Venom']
call apoc.refactor.cloneNodes([a],true) yield output
return a,b,c, output