cancel
Showing results for 
Search instead for 
Did you mean: 

iterate through two lists with foreach

mayassia
Node Link

Hi everyone,

I'm trying to use a parametrized query to create my graph.

````:param A => ["AA","AB"];
:param B => ["BA","BB"];

WITH $A as A, [10,30,30,26] as duration
FOREACH (c in A and d in duration| CREATE(:field { name:c, duration:d}));

This query does not work. I have two questions:

1- How to create list of paramters

2- How to iterate through two lists when creating a node

Thank you

1 ACCEPTED SOLUTION

glilienfield
Ninja
Ninja

You can use a double 'unwind' to get the Cartesian product of the two lists, then use 'create' directly. 

WITH [10,30,30,26] as duration
UNWIND $A as a
UNWIND duration as d
CREATE(:field { name:a, duration:d})

 

View solution in original post

3 REPLIES 3

glilienfield
Ninja
Ninja

You can use a double 'unwind' to get the Cartesian product of the two lists, then use 'create' directly. 

WITH [10,30,30,26] as duration
UNWIND $A as a
UNWIND duration as d
CREATE(:field { name:a, duration:d})

 

Thank you, it works perfectly. How about parameters. any idea please to how declare several list of parameters ?

Your welcome...Use 'params' instead, where you can define a map of parameters.

:params {A:["AA","BB"], B:["BA","BB"]}