Kirill.lv
Kirill.lv

Reputation: 77

Cypher UNWIND'ing and applying multiple labels to a node

For a case I need to create nodes and apply defined labels to that node. The definition of nodes and labels are stored in an Excel sheet which I transform in Python with the help of pandas.

Now, I have the following code that unwinds the labels, but the problem is that the resulting node gets the literal label name 'label'.

Is there a way to apply labels to a node with an unwind?

WITH s, row
FOREACH (label in row.labels |
    SET s :label)

Upvotes: 1

Views: 825

Answers (1)

Frank Pavageau
Frank Pavageau

Reputation: 11735

You can't set dynamic labels in Cypher alone, however there's an APOC procedure for that, apoc.create.addLabels(). It even takes a list, so you don't have to UNWIND.

Upvotes: 3

Related Questions