Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
10-03-2022 04:37 PM
Hello,
I want to remove/delete all the "parent" relationship between all node for Node label Traceparts.
What do I need to add to below code to remove all the relationships?
// Find all nodes with node label Traceparts
MATCH (n:Traceparts)
RETURN n
Solved! Go to Solution.
10-03-2022 05:28 PM
MATCH (n:Traceparts)-[r:parent]-(m:Traceparts)
WHERE id(n) < id(m)
DELETE r
You just need to add the relationship type to the relationship. I also added Tracepart label to the matching 'm' node in case you only want to delete relationships between these two node types. Remove it if you don't want that additional constraint.
FYI- It is generally best practice to define relationship types in all capitals, such as PARENT. I also like to write them as a verb, such as HAS_PARENT.
10-03-2022 04:49 PM
Try this, if you want to delete all relationships attached to a node with Traceparts label.
MATCH (n:Traceparts)-[r]-(m)
WHERE id(n) < id(m)
DELETE r
There is no constraint on this query other than label Tracepart. You should test it on one node first to ensure it is what you want. You can do this by added to the where clause to select just one node 'n'.
10-03-2022 05:04 PM - edited 10-03-2022 05:06 PM
Great thank you! If I would like to add one more constraint to query, to only delete relationships called "parent" for node label Traceparts. What would I need to add then?
Thank you very much!
Isak
10-03-2022 05:28 PM
MATCH (n:Traceparts)-[r:parent]-(m:Traceparts)
WHERE id(n) < id(m)
DELETE r
You just need to add the relationship type to the relationship. I also added Tracepart label to the matching 'm' node in case you only want to delete relationships between these two node types. Remove it if you don't want that additional constraint.
FYI- It is generally best practice to define relationship types in all capitals, such as PARENT. I also like to write them as a verb, such as HAS_PARENT.
All the sessions of the conference are now available online