How to duplicate Node from Node to Neo4j?

I copy part of my main Neo4j Graph (mainDB) to another graph (dupDB), doing this, how can I create a Node in dupDB that has similar properties as one in mainDB.

I would do

Node main = mainDB.getNodeByID(477); Node dup = dupDB.createNode(); 

Now I need to copy each property to main in order to manually duplex, is there any single line method for this?

+6
source share
2 answers

You can create a duplicate with a map in Neo4j 2.1 (not sure before)

 MATCH (n:Node {name: 'abc'}) WITH n AS map CREATE (copy:Node) SET copy=map RETURN copy 

If you have a restriction on the uniqueness of any of the properties, it will not be executed, although with a message ...

The node already exists with label XX and the property "property" = [value]

This can be avoided by providing a new value for a property with a unique constraint, creating a new node and copying other non-unique property values ​​from the original node.

 MATCH (n:Node {name: 'abc'}) WITH n as map CREATE (copy:Node {name: 'def'}) SET copy.property1 = map.property1 , copy.property2 = map.property2 RETURN copy 
+5
source

I do not think it existed a year ago. However, today this may solve the problem.

There is a dump command in the Neo4j shell: http://docs.neo4j.org/chunked/preview/shell-commands.html#_dumping_the_database_or_a_cypher_result_to_cypher_statements

 dump START n=node({self}) MATCH (n)-[r]-(m) return n,r,m; 

Then you can output this and send it to another database to create these nodes, properties and all.

+3
source

Source: https://habr.com/ru/post/919105/


All Articles