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.

FOREACH logic

Hi. Im new to neo. I am struggling with the logic using for each. I have two queries that I want two merge.

First:

CALL spatial.withinDistance('hikes',{lat:60.4274, lon:5.3397}, 10)
yield node, distance
return id(node), distance, node.gpx_name limit 10

which returns something like:

Now, what I want to do is to apply this cypher query:
MATCH (n:hike_data {gpx_name:"dde1b329-99f0-4582-a255-f4f6effb0389.gpx"})
with n.coors_list as list
with apoc.convert.fromJsonList(list) as clean
return clean[0][0] as lat_s, clean[0][1] as lon_s, clean[-1][0] as lat_e, clean[-1][1] as lon_e

Currently im debugging this query:
yield node, distance
FOREACH (record IN node.gpx_name |
MATCH (n:hike_data {gpx_name:record})
WITH n.coors_list as listD
WITH apoc.convert.fromJsonList(list) as clean)
RETURN clean[0][0] as lat_s, clean[0][1] as lon_s, clean[-1][0] as lat_e, clean[-1][1] as lon_e

Could you help ?
Thank you

3 REPLIES 3

MuddyBootsCode
Graph Steward

What error messages are you getting? Or what unexpected output?

I have rewritten the query to:

CALL spatial.withinDistance('hikes', {lat:60.4274, lon:5.3397}, 10)
yield node, distance
UNWIND node.gpx_name as file_name
MATCH (n:hike_data {gpx_name:file_name})
with n.coors_list as list, file_name, distance
with apoc.convert.fromJsonList(list) as clean, file_name, distance
return file_name, distance, clean[0][0] as lat_s, clean[0][1] as lon_s, clean[-1][0] as lat_e, clean[-1][1] as lon_e limit 40

But its slow ant the moment.
Now Im looking for the way to optimize it.

Its not possible to use WITH inside FOREACH .