cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Apoc.merge.node - add or append values to a given key in "onMatchProps"

Is it possible to add or append values to a given key in the "onMatchProps" portion of apoc.merge.node?

Using regular Cypher, I would use ON CREATE and ON MATCH commands to add values from different rows together

ON CREATE r.data_length = row.data_length
ON MATCH r.data_length = r.data_length + row.data_length

My issue is using apoc.merge.node, I haven't been able to determine how to reference the key created onCreateProps in the onMatchProps statement.

CALL apoc.merge.node(['Label'], identProps:{key:value, …​}, onCreateProps:{key:value,…​}, onMatchProps:{key:value,…​}})

CALL apoc.merge.node(['ip'], {key:row.ip}, {data_length:row.data_length}, {data_length:data_length + row.data_length}}) returns an error of variable "data_length" not defined.

2 REPLIES 2

apoc.merge.node is not directly capable of doing this. How about that workaround:

SET node.data_length=node.data_length + row.data_length```

On a create you're initializing `data_length=0`. Afterwards the set unconditionally adds `row.data_length` to it.

Thank you. I was hoping it would be possible to do this in one step.