apoc.lock.rels

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

Description

Acquires a write lock on the given RELATIONSHIP values.

Input arguments

Name

Type

Description

rels

LIST<RELATIONSHIP>

The list of relationships to acquire a write lock on.

Example

Given this dataset:

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

The following query acquires a write lock on a relationship before updating its property, preventing other transactions from reading or writing it until this transaction completes:

MATCH ()-[r:KNOWS]->()
CALL apoc.lock.rels([r])
SET r.since = 2020
RETURN r.since AS since
Results
since

2020

Unlike a write lock, a read lock allows other concurrent transactions to also acquire read locks on the same relationship. Only write locks - such as those required for SET or DELETE - are blocked.