Loading data and creating Nodes with apoc.merge.node

Hi All,

I'm using apoc.merge.node to load a CSV one of my fields is an array.
How do I add elements to an array property with APOC?
Somehow I need to reference what has already been entered into the array.

In the following Cypher I've labeled what I'm missing with "Elements_Already_Here" but I'm not sure how to do this? Maybe I'm on the wrong path and need to do it another way.

LOAD CSV WITH HEADERS FROM 'file:/hrsm-upload-sample.csv' AS line
CALL apoc.merge.node(
["BusinessRole"],{name:line.FullTitle},
{PositionNumber:[line.PositionNumber]},
{PositionNumber:[Elements_Already_Here] + [line.PositionNumber]}
) YIELD node
RETURN node

Thanks in advance.

Lance.

I'd use a normal merge here.

LOAD CSV WITH HEADERS FROM 'file:/hrsm-upload-sample.csv' AS line
MERGE (b:BusinessRole{name:line.FullTitle})
ON CREATE SET b.PositionNumber = [line.PositionNumber]
ON MATCH SET b.PositionNumber += [line.PositionNumber]
RETURN b

Thanks I tried it and got a syntax error with =+
Invalid input '+': expected whitespace, comment, '(', '.' or '=' (line 4, column 31 (offset: 195))

So I changed:
ON MATCH SET b.PositionNumber += [line.PositionNumber]
to:
ON MATCH SET b.PositionNumber = b.PositionNumber + [line.PositionNumber]
and it worked.

Thanks again.

1 Like