I am creating relations between nodes n and l.
Sometimes duplicate relations occur.
If a relation of this type already exists, it should merge.
So to be clear: only the relation should merge - not the nodes.
Unfortunately I have not found something like apoc.refactor.mergeRels, som i am using mergeNodes.
I get this exception, that i need to delete the relationships first. But how do I integrate a deletion of relationships into this query?
Here are the query that gives the exception (same as above from picture)
MATCH(n) WHERE ID(n) = {fromNodeId}
MATCH(l) WHERE ID(l) = {toNodeId}
CREATE (n)-[r:{relationType}]->(l)
WITH n,l
MATCH (n)-[r:{relationType}]->(l)
WITH n ORDER BY n.creationTime DESC
WITH collect(n) AS origin
CALL apoc.refactor.mergeNodes(origin, { properties: 'discard', mergeRels:true})
YIELD node
RETURN node
Thank you!