apoc.lock.all

This procedure is not considered safe to run from multiple threads. It is therefore not supported by the parallel runtime. For more information, see the Cypher Manual → Parallel runtime.

Details

Syntax

apoc.lock.all(nodes, rels)

Description

Acquires a write lock on the given NODE and RELATIONSHIP values.

Input arguments

Name

Type

Description

nodes

LIST<NODE>

The list of nodes to acquire a write lock on.

rels

LIST<RELATIONSHIP>

The list of relationships to acquire a write lock on.

Example

Given this dataset:

CREATE (:Person {name: 'Alice', age: 30})-[:KNOWS {since: 2019}]->(:Person {name: 'Bob', age: 25})

The following query acquires write locks on both nodes and the relationship in a single call before updating their properties:

MATCH (a:Person {name: 'Alice'})-[r:KNOWS]->(b:Person {name: 'Bob'})
CALL apoc.lock.all([a, b], [r])
SET a.age = 31, b.age = 26, r.since = 2020
RETURN a.name AS aName, a.age AS aAge, b.name AS bName, b.age AS bAge, r.since AS since
Results
aName aAge bName bAge since

"Alice"

31

"Bob"

26

2020

apoc.lock.all is equivalent to calling apoc.lock.nodes and apoc.lock.rels in sequence. Either list can be empty if only one entity type needs to be locked.