Modify generated query when using Neo4J-OGM

I want to implement a soft delete - deleted_at flag is null by default and set to the date when node is deleted.
I would like to add check for deleted_at is not null in all queries.
Is there any way to add such checks or modify the query before it is actually executed?

Negation in a graph database is tricky and expensive. Every query would have to load ALL relevant nodes to check each for a null value, before excluding those you wish to ignore.

All of the following are functionally equivalent to deleting a property:

  • Setting a property to null: = null
  • Remove/delete a property: REMOVE

All of the following are functionally equivalent to checking that a property is not set:

  • Checking that a property is equal to null: WHERE = null
  • Checking that a property does not exist: WHERE NOT EXISTS(
  • Checking that a property is null: WHERE IS NULL

That shows that what you're asking for is possible, but not a good thing to plan to build. If your data had a million nodes, with all but one set with a deleted_at date, every query would have to load all one million nodes, check that the date was set to remove the node from the running list, to return the single node you cared about.

What you probably should do

Add two properties:

  • is_active bool
  • deleted_at dateTime

Always set the is_active when you create your nodes. Set it to false, and the deleted_at date when you delete. Then the million-node example isn't a problem.

Thank you for taking the time to provide your thoughts.
Looks like I should be able to use the Filter parameter in loadAll query.

Be able to? yes Should? no