Search code examples
neo4jsoft-deleteneo4jphpneo4j-node

How to soft delete functionality in neo4j?


In relational databases like mysql I was used to do soft delete by setting deleted_at. And then for retrieving SELECT just get rows WHERE deleted_at IS NULL.

I am confused how to implement soft delete in neo4j database. There are multiple ways I am getting but not sure which method or combination will have more advantages.

I also read Neo4j: implementing soft delete with optional relationships but not helping.

  1. Just set property of node deleted_at.
  2. Remove node label and change by prefix "_" like "Student" will become "_Student"
  3. Remove relationship and change by prefix "_" like "TEACHES" will become "_TEACHES"

Which will be best way or combination or other way to achieve soft delete in neo4j?


Solution

  • I think have a deleted_at property for node. In which you can store deleted time-stamp.

    And at the time of fetching nodes information you can check deleted_at IS NULL. like -

      MATCH (n:node)
      WHERE n.deleted_at IS NULL
      RETURN n;
    

    Storing time-stamp you can get when node is deleted.

    You can also have relationship deleted_by between user who deleted the node. So that you can find out who deleted node.