Search code examples
node.jsmongoosefeathersjssoft-delete

How to do soft delete in feathersJs using mongoose for mongoDb database


I want to implement the soft delete feature in the project I am working on currently. The project is using feathersjs and mongoose. If anybody is having any idea how to implement it inside feathers hooks


Solution

  • we can use hooks collection created by feathers community feathers-hooks-common

    use npm install feathers-hooks-common to import it in our library.

     import {softDelete} from 'feathers-hooks-common';
    
        export default {
          before: {
            all: [
    //it takes an object as its parameter. in this case i passed an empty object
          softDelete({}),
        ],
        find: [],
        get: [],
        create: [],
        update: [],
        patch: [],
        remove: []
          }
        }
    

    also add deleted field of type boolean in your schema