2
votes

How to remove bidirectional relation between two nodes of same label and make it single relation between those two nodes irrespective of the direction.

For example:

(a:Label1)-[r]->(b:Label1) && (b:Label1)-[r]->(a:Label1)

What I need is either of a-[r]->b or b-[r]->a

If I use this:

 MATCH (a:Label1)-[r]->(b:Label1)

It is removing all relations.

Is it because of same label?

1

1 Answers

0
votes

Use collect and tail function:

MATCH (a:Label1)-[r]-(b:Label1)
WITH a, b, collect(r) as rels
UNWIND tail(rels) as rel
DELETE rel