Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
11-22-2021 07:35 AM
Hi,
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.
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);
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
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 on refactor.cloneNodes
Regards
Solved! Go to Solution.
11-22-2021 03:10 PM
I can answer your first question, with apoc.refactor.cloneSubgraph: apoc.refactor.cloneSubgraph - APOC Documentation
e.g.
MATCH (s) where s.version_id = 'version-1'
WITH collect (s) as nodes
call apoc.refactor.cloneSubgraph(nodes)
YIELD output as o
SET o.version_id = 'version-2'
RETURN count (o)
There's potential to tune the procedure with the config
argument, but I haven't looked too much into it.
11-22-2021 03:10 PM
I can answer your first question, with apoc.refactor.cloneSubgraph: apoc.refactor.cloneSubgraph - APOC Documentation
e.g.
MATCH (s) where s.version_id = 'version-1'
WITH collect (s) as nodes
call apoc.refactor.cloneSubgraph(nodes)
YIELD output as o
SET o.version_id = 'version-2'
RETURN count (o)
There's potential to tune the procedure with the config
argument, but I haven't looked too much into it.
All the sessions of the conference are now available online