Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
10-17-2019 06:27 AM
Hi, how to sort the id(n) inside the collect based on the distances by ascending order.
the below query doesn't sort the distance.
MATCH (n:PointNodes)
WITH n, distance(point({longitude:n.lon,latitude:n.lat}), point({ longitude: -1.7444, latitude: 23.7971 })) as dist
where dist < 200
RETURN collect(id(n))
Solved! Go to Solution.
10-17-2019 09:41 AM
Hello,
No sorting is taking place because you haven't specified any kind of ordering. You need to sort before the collect, which will ensure the resulting list is ordered:
MATCH (n:PointNodes)
WITH n, distance(point({longitude:n.lon,latitude:n.lat}), point({ longitude: -1.7444, latitude: 23.7971 })) as dist
WHERE dist < 200
WITH n, dist
ORDER BY dist ASC
RETURN collect(id(n))
10-17-2019 09:41 AM
Hello,
No sorting is taking place because you haven't specified any kind of ordering. You need to sort before the collect, which will ensure the resulting list is ordered:
MATCH (n:PointNodes)
WITH n, distance(point({longitude:n.lon,latitude:n.lat}), point({ longitude: -1.7444, latitude: 23.7971 })) as dist
WHERE dist < 200
WITH n, dist
ORDER BY dist ASC
RETURN collect(id(n))
All the sessions of the conference are now available online