Hi,
Problem
Using apoc.refactor.cloneNodes
, I'm trying to duplicate a graph with a certain condition (all nodes containing a property {"version_id": "version-1"). Problem: extra connections between the previous (existing graph) & new graph also gets created.
Base Graph
CREATE (n:Catalog {catalog_id : 'catalog-1', name: 'Catalog 1', version_id: 'version-1'});
CREATE (n:SalesCategory {sales_category_id : 'category-1', version_id: 'version-1'});
CREATE (n:SalesCategory {sales_category_id : 'category-2', version_id: 'version-1'});
MATCH (c:Catalog {catalog_id: 'catalog-1'}), (s:SalesCategory {sales_category_id: 'category-1', version_id: 'version-1'}) CREATE (c)-[:HAS_SALES_CATEGORY {catalog_id: 'catalog-1', is_deleted: false}]->(s);
MATCH (c:Catalog {catalog_id: 'catalog-1'}), (s:SalesCategory {sales_category_id: 'category-2', version_id: 'version-1'}) CREATE (c)-[:HAS_SALES_CATEGORY {catalog_id: 'catalog-1', is_deleted: false}]->(s);
Clone Query
MATCH (s) where s.version_id = 'version-1'
WITH collect (s) as nodes
call apoc.refactor.cloneNodes(nodes, true, ['version_id'])
YIELD output as o
SET o.version_id = 'version-2'
RETURN count (o)
Here's the result
What I expect
Questions
- How to clone relations while cloning the graph, but prevent creating extra relations between old & new graphs ?
- Since the goal is to clone a graph based on a specific property (
version_id
here) & updating it to a new value/version, I'm excluing the version_id param when cloning & then updating output's version_id (coming from YEILD), is there a better way of doing this ? since I didn't find any info. on overriding a property onrefactor.cloneNodes
- Is it safe/a good practice to clone nodes (using apoc.refactor) to clone millions of nodes ?
Regards