Search code examples
node.jsneo4jcyphernode-neo4j

After query execution detect that merge created node, not matched


Simple question, that I'm having hard time googling. Using cypher via node-neo4j, I want to run some logic after query, but only if my MERGE created node (i.e ON CREATE inside query was triggered), not matched it. How can I achieve this?


Solution

  • You could have created_at and matched_at fields with MERGE and then check them for equality when you return the object:

    MERGE (f:Foo)
    ON CREATE SET f.created_at = timestamp()
    ON MATCH SET f.matched_at = timestamp()
    RETURN f