Hello, friends! I'm trying to write an APOC trigger which does some rather complex behavior and I'm having some issues. Can someone help me?
I want to guarantee that all relationships of type "WORKS_AT" start in an "Intern" node and end in a "Company" node, so I wrote the following trigger:
CALL apoc.trigger.add("WORKS_AT",
"UNWIND [rel in $createdRelationships WHERE type(rel) = 'WORKS_AT'] AS rel
WITH startNode(rel) AS start, endNode(rel) AS end
MATCH (start)-[:WORKS_AT]->(end)
WHERE not('Intern' IN labels(start)) OR not('Company' IN labels(end))
DETACH DELETE start, end",
{phase:'after'})
Which should delete the start and end nodes when a "WORKS_AT" relationship doesn't respect this rule. I wrote the following command to test it:
CREATE (john:Intern { name: "John" })
CREATE (google:Company { domain: "[google.com](http://google.com/)", name: "Google" })
CREATE (peter:Unemployed { name: "Peter" })
CREATE (john)-[:WORKS_AT]->(google)
CREATE (peter)-[:WORKS_AT]->(google)
But what happens when I run it is that it keeps hanging and just won't finish. I tried using Halin to check if the database instance was out of memory or having any issues, but it didn't show anything relevant.
Does anyone know why is it hanging and what can I do about it? I've already upped "dbms.memory.heap.initial_size" and "dbms.memory.heap.max_size" to 2G.