Atomic property updates
The APOC library contains procedures that can be used for thread-safe updating of properties on nodes and relationships.
Procedures for thread-safe updating of properties on nodes and relationships
Qualified Name | Type |
---|---|
|
Procedure |
|
Procedure |
|
Procedure |
|
Procedure |
|
Procedure |
|
Procedure |
Examples
The below examples will further explain these procedures.
CREATE (p:Person {name:'Tom',age: 40})
CREATE (p:Person {name:'Will',age: 35})
CREATE (p:Person {name:'David', children: ['Anne','Sam','Paul']})
CREATE (p:Person {name:'John', cars: ['Class A','X3','Focus']})
CREATE (p:Person {name:'Ryan', salary1:1800, salary2:1500})
age
for Tom
:MATCH (n:Person {name:'Tom'})
CALL apoc.atomic.add(n,'age',10,5)
YIELD oldValue, newValue
RETURN n
n |
---|
{"name":"Tom","age":50} |
age
for Tom
:MATCH (n:Person {name:'Tom'})
CALL apoc.atomic.subtract(n,'age',10,5)
YIELD oldValue, newValue
RETURN n
n |
---|
{"name":"Tom","age":40} |
iam
to the name
property for Will
:MATCH (p:Person {name:'Will',age: 35})
CALL apoc.atomic.concat(p,"name",'iam',5)
YIELD newValue
RETURN p
p |
---|
{"name":"William","age":35} |
Mary
in position 2 of children
list:MATCH (p:Person {name:'David'})
CALL apoc.atomic.insert(p,'children',2,'Mary',5)
YIELD newValue
RETURN p
p |
---|
{"name":"David","children":["Anne","Sam","Mary","Paul"]} |
X3
, which is at position 1, from the array cars
MATCH (p:Person {name:'John'})
CALL apoc.atomic.remove(p,'cars',1,5)
YIELD newValue
RETURN p
p |
---|
{"name":"John","cars":["Class A","Focus"]} |
salary1
with the result of an expression:MATCH (p:Person {name:'Ryan'})
CALL apoc.atomic.update(p,'salary1','n.salary1*3 + n.salary2',5)
YIELD newValue
RETURN p
In the operation
expression (3rd parameter) the entity passed in as container
(1st parameter) is referred to using the variable n
. If the node or relationship is renamed (as in the example above), it is still necessary to refer to it in the expression as n
.
p |
---|
{"name":"Ryan","salary1":6900,"salary2":1500} |