【问题标题】:How to do soft delete in feathersJs using mongoose for mongoDb database如何在feathersJs中使用mongoose for mongoDb数据库进行软删除
【发布时间】:2022-02-11 14:02:25
【问题描述】:

我想在我目前正在处理的项目中实现软删除功能。该项目使用feathersjs和猫鼬。如果有人知道如何在羽毛钩中实现它

【问题讨论】:

  • 软删除的定义。
    一种将已删除数据保存在数据库中的简单方法。数据库术语中的“软删除”意味着您在现有表上设置一个标志,表明一条记录已被删除,而不是实际删除该记录。

标签: node.js mongoose feathersjs soft-delete


【解决方案1】:

我们可以使用羽毛社区feathers-hooks-common创建的钩子集合

使用 npm install feathers-hooks-common 将其导入我们的库中。

 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: []
      }
    }

还在架构中添加 boolean 类型的已删除字段

【讨论】:

    猜你喜欢
    • 2012-04-22
    • 2021-12-21
    • 2016-12-24
    • 1970-01-01
    • 2015-07-27
    • 2021-10-06
    • 2012-02-10
    • 1970-01-01
    相关资源
    最近更新 更多