apoc.merge.node

Procedure

apoc.merge.node(labels LIST<STRING>, identProps MAP<STRING, ANY>, onCreateProps MAP<STRING, ANY>, onMatchProps MAP<STRING, ANY>) - merges the given NODE values with the given dynamic labels.

Signature

apoc.merge.node(labels :: LIST<STRING>, identProps :: MAP, onCreateProps = {} :: MAP, onMatchProps = {} :: MAP) :: (node :: NODE)

Input parameters

Name Type Default Description

labels

LIST<STRING>

null

The list of labels used for the generated merge statement. Passing null or an empty list will merge a node without any labels. null or empty strings within the list are not supported.

identProps

MAP

null

Properties on the node that are always merged.

onCreateProps

MAP

{}

Properties that are merged when a node is created.

onMatchProps

MAP

{}

Properties that are merged when a node is matched.

Output parameters

Name Type

node

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;
Table 1. 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);
Table 2. Results
node

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