cancel
Showing results forΒ 
Search instead forΒ 
Did you mean:Β 

Create a edge property using the properties of the 2 nodes it is connected to

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

1 ACCEPTED SOLUTION

glilienfield
Ninja
Ninja

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

View solution in original post

1 REPLY 1

glilienfield
Ninja
Ninja

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