apoc.atomic.update

Details

Syntax

apoc.atomic.update(container, propertyName, operation [, retryAttempts ]) :: (container, property, oldValue, newValue)

Description

Updates the value of a property with a Cypher operation.

Input arguments

Name

Type

Description

container

ANY

The node or relationship with the property to be updated.

propertyName

STRING

The name of the property to be updated.

operation

STRING

The operation to perform to update the property.

retryAttempts

INTEGER

The max retry attempts. The default is: 5.

Return arguments

Name

Type

Description

container

ANY

The updated node or relationship.

property

STRING

The name of the updated property.

oldValue

ANY

The original value on the property.

newValue

ANY

The new value on the property.

Usage examples

The examples in this section are based on the following sample graph:

CREATE (:Person {name:'Tom',age: 40})
CREATE (:Person {name:'Will',age: 35})
CREATE (:Person {name:'David', children: ['Anne','Sam','Paul']})
CREATE (:Person {name:'John', cars: ['Class A','X3','Focus']})
CREATE (:Person {name:'Ryan', salary1:1800, salary2:1500});

The following updates 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 oldValue, newValue
RETURN oldValue, newValue;

In the operation expression (3rd parameter) the entity passed in as container (1st parameter) is referred to using the variable n. If we rename our node/rel (as in the example above) we still have to refer to it in the expression as n.

Results
oldValue newValue

1800

6900