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?, onCreateProps = {} :: MAP?, onMatchProps = {} :: MAP?) :: (node :: NODE?)
Input parameters
Name | Type | Default | Description |
---|---|---|---|
labels |
LIST? OF STRING? |
null |
The list of labels used for the generated merge statement. Passing |
identProps |
MAP? |
null |
Properties 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. |
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":
CALL apoc.merge.node.eager(
["Person", "Actor"],
{name: "Tom Hanks"},
{created: datetime()},
{lastSeen: datetime()}
);
MERGE (node:Person:Actor {name: "Tom Hanks"})
ON CREATE SET node.created = datetime()
ON MATCH SET node.lastSeen = datetime()
RETURN node;
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);
node |
---|
(:Human:MovieStar {name: "Tom Cruise", placeOfBirth: "Syracuse, New York, United States"}) |