apoc.merge.relationship.eager

Details

Syntax

apoc.merge.relationship.eager(startNode, relType, identProps, onCreateProps, endNode [, onMatchProps ]) :: (rel)

Description

Merges the given RELATIONSHIP values with the given dynamic types/properties eagerly.

Input arguments

Name

Type

Description

startNode

NODE

The start node of the relationship.

relType

STRING

The type of the relationship.

identProps

MAP

Properties on the relationship that are always merged.

onCreateProps

MAP

Properties that are merged when a relationship is created.

endNode

NODE

The end node of the relationship.

onMatchProps

MAP

Properties that are merged when a relationship is matched. The default is: {}.

Return arguments

Name

Type

Description

rel

RELATIONSHIP

The updated relationship.

Example

Given this dataset:

CREATE (:Person {name: 'Alice'}), (:Person {name: 'Bob'})

The following query merges a KNOWS relationship between two existing nodes, using id as the identifying property and since as an on-create property:

MATCH (a:Person {name: 'Alice'}), (b:Person {name: 'Bob'})
CALL
  apoc.merge.relationship.eager(
    a,
    'KNOWS',
    {id: 1},
    {since: 2019},
    b,
    {}
  )
  YIELD rel
RETURN type(rel) AS type, rel.id AS id, rel.since AS since
Results
type id since

"KNOWS"

1

2019

Produces the same result as apoc.merge.relationship. The eager variant fully materializes all results before returning, which prevents conflicts when the procedure is used inside a larger query that also reads or writes relationships of the same type. Calling the procedure again with the same identProps returns the existing relationship without creating a duplicate; any onMatchProps are applied to the matched relationship instead.