apoc.merge.node
Syntax |
|
||
Description |
Merges the given |
||
Input arguments |
Name |
Type |
Description |
|
|
The list of labels used for the generated MERGE statement. |
|
|
|
Properties on the node that are always merged. |
|
|
|
Properties that are merged when a node is created. The default is: |
|
|
|
Properties that are merged when a node is matched. The default is: |
|
Return arguments |
Name |
Type |
Description |
|
|
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":
CALL apoc.merge.node(
["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($labels, $identityProperties);
node |
---|
(:Human:MovieStar {name: "Tom Cruise", placeOfBirth: "Syracuse, New York, United States"}) |