apoc.atomic.subtract

Details

Syntax

apoc.atomic.subtract(container, propertyName, number [, retryAttempts ]) :: (container, property, oldValue, newValue)

Description

Sets the property of a value to itself minus the given INTEGER or FLOAT value. The procedure then sets the property to the returned sum.

Input arguments

Name

Type

Description

container

ANY

The node or relationship that contains the property from which the value will be subtracted.

propertyName

STRING

The name of the property from which the value will be subtracted.

number

INTEGER | FLOAT

The number to subtract.

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 subtracts 10 from the property age for Tom:

MATCH (n:Person {name:'Tom'})
CALL apoc.atomic.subtract(n,'age',10,5)
YIELD oldValue, newValue
RETURN oldValue, newValue;
Results
oldValue newValue

40

30