Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
11-28-2022 01:50 AM
I have been trying to create a new edge property using the property of the nodes it has been connected to but am unable to complete the cypher query.
Database: Using the neo4j gds examples airports database
Task: set a property "avgPageRank" to the "has_route" relation from the two nodes its connected to having the property page rank.
````match (p:Airport)-[r:HAS_ROUTE]->(q:Airport)
with collect(r) as routes
foreach(route in routes | SET route.avgPageRank = p.pagerank + q.pagerank)```
Here I am unable to get the access to p and q, the starting airport and the ending airport
Solved! Go to Solution.
11-28-2022 02:53 AM - edited 11-28-2022 02:54 AM
The variables ‘p’ and ‘q’ are out of scope when you try to reference them in the forEach block. You need to pass them in your ‘with’ clause.
I don’t see the need for the ‘collect’, followed by ‘forEach’, as you are setting each relationship independently based on their end nodes.
this should work just as well:
match (p:Airport)-[r:HAS_ROUTE]->(q:Airport)
SET r.avgPageRank = p.pagerank + q.pagerank
11-28-2022 02:53 AM - edited 11-28-2022 02:54 AM
The variables ‘p’ and ‘q’ are out of scope when you try to reference them in the forEach block. You need to pass them in your ‘with’ clause.
I don’t see the need for the ‘collect’, followed by ‘forEach’, as you are setting each relationship independently based on their end nodes.
this should work just as well:
match (p:Airport)-[r:HAS_ROUTE]->(q:Airport)
SET r.avgPageRank = p.pagerank + q.pagerank
All the sessions of the conference are now available online