Reputation: 101
when you create a relationship with a label on the arrow. how do sometime in the future to change the label without delete the relationship? is possible? can You also modify a set of relationships with the same label, in another label?
edit I write this to create new and copy property
MATCH (m)-[old:INVIA_DATI]->(n)
WHERE ID(m) = 11 AND ID(n) = 13
CREATE (m)-[new:INVIA2{name:old.name}]->(n)
DELETE old
RETURN m, new, n
Now work but if I have 4 property like name,color,connector , other ? Thanks for all!
Upvotes: 1
Views: 853
Reputation: 3739
Well you can create a new relationship like this:
MATCH (m)-[old:OLD_RELATIONSHIP]->(n)
CREATE (m)-[new:NEW_RELATIONSHIP]->(n)
DELETE old
RETURN m, new, n
For your example:
MATCH (m)-[old:INVIA_DATI]->(n)
WHERE ID(m) = 97 AND ID(n) = 115
CREATE (m)-[new:INVIA2]->(n)
DELETE old
RETURN m, new, n
Explanation:
MATCH (m)-[old:INVIA_DATI]->(n)
WHERE ID(m) = 97 AND ID(n) = 115
These two lines match your nodes with IDs 97 and 115 respectively where (and only where) an INVIA_DATI
relationship exists between them. m
is bound to the node with node ID 97, n
is bound to the node with ID 115 and old
is bound to the relationship. You could use any values you like instead of n, m and old.
CREATE (m)-[new:INVIA2]->(n)
This line creates the new relationship between the bound nodes m
and n
with the type INVIA2
you could additionally set properties here. If you want to prevent duplicates being created you can use MERGE
instead of create.
DELETE old
This deletes the old relationship.
RETURN m, new, n
Return the bound values. You don't have to do that if you don't want to, but it's handy in the console to see what has just happened.
And if you need to set a property you can do:
CREATE (m)-[new:INVIA2{propname:old.propname}]->(n)
This will set the propname
relationship property with the value from the original propname property, you can set as many properties as you like in this way.
Upvotes: 2
Reputation: 3308
We have the concept of both a Label
and a Relationship Type
in the labeled property graph data model of Neo4j.
For labels on nodes, the following rules apply:
Labels
allow you to group nodes together by a role.Labels
only apply to nodes and a node can have zero or more labels.For relationships, the following rules apply:
Relationship Types
are applied only to relationships.Relationship Type
. Relationship Types
cannot be changed on a relationship, you must delete the
relationship and replace it with a new one with a different type.Upvotes: 1