I have two nodes A and B. They have a relationship R, with some property P, on this relationship.
How I can update this relationship R, with a new value for P? I tried merge, but this creates a new relationship, but I want to update the existing one.
You cannot rename an already existing relationship. You'd have to run through all relationships, create the new one in parallel (including all properties) and then remove the old one.
To create a relationship between two nodes, we first get the two nodes. Once the nodes are loaded, we simply create a relationship between them. The created relationship is returned by the query.
Properties are stored as a linked list of property records, each holding a key and value and pointing to the next property. Each node and relationship references its first property record. The Nodes also reference the first relationship in its relationship chain. Each Relationship references its start and end node.
With UNWIND , you can transform any list back into individual rows.
Match on your nodes and the relationship, then use SET to update the relationship property. For example:
MATCH (a {name:"A"})-[r]-(b {name:"B"})
SET r.P = "bar"
It's generally best, when looking up specific nodes, to use labels in the query, and have an index or unique constraint (whichever makes the most sense) to speed up your lookups.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With