cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Cypher & Neo4j : for loop with Cypher request

LJRB
Graph Buddy

I have a list of words that I want to use as seed labels in Neo4j.

These labels are renewed everyday so I would like to automate my Cypher requests.

Here is the list I have today:

List : list_of_labels = ['crise sanitaire', 'face crise', 'confinement avril', 'crise coronavirus', 'virus guerre']

I tried this with variables in my Cypher requests:

def create_seed_property(tx, i): j = 0 while j < len(list_of_labels): tx.run(" MATCH (n:ARTICLE {label: $i}) SET n.seed_label = $j RETURN n ") j +=1

And next I did this:

for i in list_of_labels: session.read_transaction(create_seed_property(i))

I don't know where I'm wrong.

1 REPLY 1

You can use UNWIND to process elements of a list. Provided you pass the list_of_labels as a parameter, you can process it like so:

UNWIND $list_of_labels as seed_label
MATCH (n:ARTICLE {label: $i}) 
SET n.seed_label = seed_label 
RETURN n