apoc.lock.nodes

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.nodes(nodes)

Description

Acquires a write lock on the given NODE values.

Input arguments

Name

Type

Description

nodes

LIST<NODE>

The list of nodes 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 a write lock on a node before updating its property, preventing other transactions from reading or writing it until this transaction completes:

MATCH (n:Person {name: 'Alice'})
CALL apoc.lock.nodes([n])
SET n.age = n.age + 1
RETURN n.name AS name, n.age AS age
Results
name age

"Alice"

31