apoc.atomic.subtract

Procedure

apoc.atomic.subtract(container ANY, propertyName STRING, number INTEGER \| FLOAT, retryAttempts INTEGER) - 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.

Signature

apoc.atomic.subtract(container :: ANY, propertyName :: STRING, number :: INTEGER \| FLOAT, retryAttempts = 5 :: INTEGER) :: (container :: ANY, property :: STRING, oldValue :: ANY, newValue :: ANY)

Input parameters

Name Type Default

container

ANY

null

propertyName

STRING

null

number

INTEGER | FLOAT

null

retryAttempts

INTEGER

5

Output parameters

Name Type

container

ANY

property

STRING

oldValue

ANY

newValue

ANY

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;
Table 1. Results
oldValue newValue

40

30