Search code examples
databaseneo4jtransactionscypher

How can i fail Neo4j transaction if validation query fails


I have a Neo4j transaction that is composed from several cypher queries.

for idempotency sake, i'd like to include a validation query that will fail the transaction if needed.

any idea how can i do that?

i was looking how to return an error or throw exception but it doesn't seem so popular as i cant find anything about it

whats the best practice that is recommended here?


Solution

  • You could use apoc.util.validate to throw an error from inside cypher.

    Example:

    CALL apoc.util.validate(true, "MY ERROR MESSAGE")