apoc.merge.node

Details

Syntax

apoc.merge.node(labels, identProps [, onCreateProps, onMatchProps ]) :: (node)

Description

Merges the given NODE values with the given dynamic labels.

Input arguments

Name

Type

Description

labels

LIST<STRING>

The list of labels used for the generated MERGE statement.

identProps

MAP

Properties on the node that are always merged.

onCreateProps

MAP

Properties that are merged when a node is created. The default is: {}.

onMatchProps

MAP

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

Return arguments

Name

Type

Description

node

NODE

The updated node.

Usage Examples

This procedure provides a more flexible way of merging nodes than Cypher’s MERGE clause.

The example below shows equivalent ways of merging a node with the Person and Actor labels, with a name property of "Tom Hanks":

apoc.merge.node
CALL apoc.merge.node(
  ["Person", "Actor"],
  {name: "Tom Hanks"},
  {created: datetime()},
  {lastSeen: datetime()}
);
MERGE clause
MERGE (node:Person:Actor {name: "Tom Hanks"})
ON CREATE SET node.created = datetime()
ON MATCH SET node.lastSeen = datetime()
RETURN node;
Results
node

(:Person:Actor {name: "Tom Hanks", created: 2020-11-24T11:33:39.319Z})

But this procedure is mostly useful for merging nodes that have dynamic labels or properties. For example, we might want to create a node with labels or properties passed in as parameters.

The following creates labels and properties parameters:

:param labels =>  (["Human", "MovieStar"]);
:param identityProperties => ({name: "Tom Cruise", placeOfBirth: "Syracuse, New York, United States"});

The following creates a node with labels and properties based on the previously defined parameters:

CALL apoc.merge.node($labels, $identityProperties);
Results
node

(:Human:MovieStar {name: "Tom Cruise", placeOfBirth: "Syracuse, New York, United States"})