apoc.merge.nodeWithStats

Details

Syntax

apoc.merge.nodeWithStats(labels, identProps [, onCreateProps, onMatchProps ]) :: (stats, node)

Description

Merges the given NODE values with the given dynamic labels. Provides queryStatistics in the result.

Input arguments

Name

Type

Description

labels

LIST<STRING>

The list of labels used for the generated MERGE statement.

identProps

MAP

Properties on the node that are always merged.

onCreateProps

MAP

Properties that are merged when a node is created. The default is: {}.

onMatchProps

MAP

Properties that are merged when a node is matched. The default is: {}.

Return arguments

Name

Type

Description

stats

MAP

The returned query statistics.

node

NODE

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:

CALL
  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
Results
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.