apoc.merge.nodeWithStatsProcedure
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 returned query statistics. |
|
|
|
The updated node. |
|
Example
The following query merges a Person node using id as the identifying property and name and age as on-create properties, returning the node alongside query statistics:
MERGEMERGE (node:Person {id: 1})
ON CREATE SET node.name = 'Alice', node.age = 30
RETURN
node.id AS id,
node.name AS name,
node.age AS age
apoc.merge.nodeWithStatsCALL
apoc.merge.nodeWithStats(
['Person'],
{id: 1},
{name: 'Alice', age: 30},
{}
)
YIELD node, stats
RETURN
node.id AS id,
node.name AS name,
node.age AS age,
stats.nodesCreated AS nodesCreated,
stats.propertiesSet AS propertiesSet
Cypher’s MERGE does not return nodesCreated or propertiesSet as columns.
They show up in the query statistics (e.g. "Added 1 label, created 1 node, set 3 properties") instead.
|
| id | name | age | nodesCreated | propertiesSet |
|---|---|---|---|---|
1 |
"Alice" |
30 |
1 |
3 |
nodesCreated is 1 because no node with id: 1 existed.
propertiesSet is 3, covering all properties written: id, name, and age.
Calling the procedure again with the same identProps, the existing node is matched instead: nodesCreated becomes 0 and only the onMatchProps changes are reflected in propertiesSet.