apoc.merge.node.eager

Procedure APOC Core

apoc.merge.node.eager(['Label'], identProps:{key:value, …​}, onCreateProps:{key:value,…​}, onMatchProps:{key:value,…​}}) - merge nodes eagerly, with dynamic labels, with support for setting properties ON CREATE or ON MATCH

Signature

apoc.merge.node.eager(label :: LIST? OF STRING?, identProps :: MAP?, props = {} :: MAP?, onMatchProps = {} :: MAP?) :: (node :: NODE?)

Input parameters

Name Type Default

label

LIST? OF STRING?

null

identProps

MAP?

null

props

MAP?

{}

onMatchProps

MAP?

{}

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.create.node
CALL apoc.merge.node.eager(
  ["Person", "Actor"],
  {name: "Tom Hanks"},
  {created: datetime()},
  {lastSeen: datetime()}
);
CREATE 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.eager($labels, $identityProperties);
Table 2. Results
node

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