I am copying part of my Main Neo4j Graph(mainDB) into another Graph (dupDB), while doing so 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 have to copy each property in main to dup manually, is there any one-line method to do this?
You can create a duplicate with a map in Neo4j 2.1 (not sure of earlier)
MATCH (n:Node {name: 'abc'})
WITH n AS map
CREATE (copy:Node)
SET copy=map
RETURN copy
If you have a uniqueness constraint on any of the properties it will fail though with the message...
Node already exists with label XX and property "property"=[value]
You can avoid that by supplying a new value for the property with the uniqueness constraint, creating the new node and copying the 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With