Neo4j Add / update properties if node exists

I want to be able to update/enlarge my Neo4j database to download a newer version of this database or part of it.

From what I found, I can use MERGE to add new nodes only if they do not already exist. But in this process, how do I make the slimmed way to add new properties for an existing node, if they do not exist?

I e if I have node 'John' of 'Age:34' and 'Hair:brown' and download 'John'/'Age:34'/'Coat:Yellow' - how do I get 'John'/'Age:34'/'Hair:brown'/'Coat:Yellow' .

+7
neo4j cypher
source share
1 answer

You can combine node into John (or primary identifying attribute). Then set the properties after a successful merge.

You can set them all at once using the map for all attributes

 merge (n:Node {name: 'John'}) set n = {name: 'John', age: 34, coat: 'Yellow', hair: 'Brown'} return n 

If you just wanted to replace the attributes of age and coat , you can do it instead.

 merge (n:Node {name: 'John'}) set n.age = 34, n.coat = 'Yellow' return n 

Or you can add it as a map too

 merge (n:Node {name: 'John'}) set n += {age: 34, coat: 'Yellow'} return n 
+13
source share

All Articles