apoc.atomic.insert

Procedure

apoc.atomic.insert(container ANY, propertyName STRING, position INTEGER, value ANY, retryAttempts INTEGER) - inserts a value at position into the LIST<ANY> value of a property. The procedure then sets the result back on the property.

Signature

apoc.atomic.insert(container :: ANY, propertyName :: STRING, position :: INTEGER, value :: ANY, retryAttempts = 5 :: INTEGER) :: (container :: ANY, property :: STRING, oldValue :: ANY, newValue :: ANY)

Input parameters

Name Type Default

container

ANY

null

propertyName

STRING

null

position

INTEGER

null

value

ANY

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 adds Mary in position 2 of children list:

MATCH (p:Person {name:'David'})
CALL apoc.atomic.insert(p,'children',2,'Mary',5)
YIELD oldValue, newValue
RETURN oldValue, newValue;
Table 1. Results
oldValue newValue

["Anne", "Sam", "Paul"]

["Anne", "Sam", "Mary", "Paul"]