β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