Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
08-14-2022 10:58 AM
I have a data structure similar to the one below:
[
{
"ID":"1",
"team":[
"team1",
"team2"
],
"group":[
"group1",
"group2"
]
},
{
"ID":"2",
"team":[
],
"group":[
"group1"
]
},
{
"ID":"3",
"team":[
"team1",
"team3"
],
"group":[
"group3"
]
}
]
Where I have a list of dictionaries, which have a list. I want to be able to run a query that iterates over the list like so:
for i in main_list:
for j in i.team:
# Code Here
for k in i.group:
# Code Here
But, when I try to do an UNWIND, such as the one below:
UNWIND main_list as i
MERGE (n:USER {id:i.id})
UNWIND i.teams as team
MERGE (t:TEAM {name:team})
MERGE (n)-[:BELONGS_TO]->(t)
WITH i,n
UNWIND i.groups as group
MERGE (g:GROUP {name:group})
MERGE (n)-[:BELONGS_TO]->(g)
RETURN count(main_list)
I think what the cypher query is doing is, but I'm not exactly sure.
for i in main_list:
for j in i.team:
# Code Here
for k in i.group:
# Code Here
What is the best approach to handle multiple inner loops?
Thanks!
Solved! Go to Solution.
08-14-2022 11:50 AM
08-14-2022 11:50 AM
Use ‘forEach’ for each inner list instead of ‘unwind’.
08-29-2022 09:49 AM
That worked, thanks!
All the sessions of the conference are now available online