【问题标题】:Getter/Setter Mongoose FeathersJS on get or findGetter/Setter Mongoose FeathersJS on get 或 find
【发布时间】:2021-11-10 16:05:36
【问题描述】:

当在 mongoose 模式中使用 getter 或 setter 时,它只在 create 时调用。 模式选项中的 toJSON 或 toObject 中的转换函数也是如此。 在获取或查找时没有 console.log()

const schema = new Schema({
    imageId: {
      type: String,
      get: (v) => {
        console.log('Here');
        return v;
      }
    },
  }, {
    timestamps: true
    toJSON: {
      transform: (doc, ret, options) => {
        console.log('Here too');
      }
    }
    }
  });

你知道如何让它们在 get 和 find 上工作吗?

谢谢

【问题讨论】:

    标签: javascript mongodb mongoose getter-setter feathersjs


    【解决方案1】:

    使用 Mongoose 模型属性时,lean service option 需要设置为 false

    【讨论】:

      猜你喜欢
      • 2011-12-02
      • 2012-12-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-13
      • 1970-01-01
      • 1970-01-01
      • 2014-03-16
      相关资源
      最近更新 更多