Clone nodes and relationships with Cypher

大城市里の小女人 提交于 2020-01-05 05:50:08

问题


Is it possible to clone arbitrary nodes and relationships in a single Cypher neo4j 2.0 query? 'Arbitrary' reads 'without specifying their labels and relationship types'. Something like:

MATCH (node1:NodeType)-[e]->(n)
CREATE (clone: labels(n)) set clone=n set clone.prop=1 
CREATE (node1)-[e1:type(e)]->(clone) set e1=e set e1.prop=2

is not valid in Cypher, so one cannot simply get labels from one node or relationship and assign them to another, because labels are compiled into the query literally.

Sure, labels and relation types are important for MATCH and WHERE for producing effective query plan, but isn't CREATE making another case?


回答1:


The easiest way to clone parts of a graph is to use the dump command in Neo4j shell. dump generates cypher create statements from your return clauses. The result of dump can be appied to the graph database to create clones.



来源:https://stackoverflow.com/questions/20779579/clone-nodes-and-relationships-with-cypher

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!