Home > database >  Getter/Setter Mongoose FeathersJS on get or find
Getter/Setter Mongoose FeathersJS on get or find

Time:09-22

When using getter or setter in a mongoose schema, it is only call on create. It's the same for a transform function in toJSON or toObject in schema options. On a get or find there is no 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');
      }
    }
    }
  });

Do you know how make them work on get and find ?

Thanks

CodePudding user response:

When using Mongoose model properties the lean service option needs to be set to false.

  • Related