mongoose-lean-virtuals icon indicating copy to clipboard operation
mongoose-lean-virtuals copied to clipboard

how to set lean default with typegoose

Open minefujiko9293 opened this issue 1 year ago • 1 comments

image

In typegoose,
i want to no typing '{ virtuals : true }' but plugin can auto lean it. when i use the mongooseLeanDefaults, i can use

@plugin(mongooseLeanDefaults as any, { defaults: true })
@plugin(mongooseLeanVirtuals as any, {
  enabledByDefault: true,
  virtuals: true,
  lean: true,
})
export class SyncBBRecord{
 @prop({ default: 'default_name' })
  name?: string;

  get vv() {
    return 'vv';
  }
}

const result = await this.mSyncBBRecord.findOne({}).lean();
console.log(result.name); // name has default value.
console.log(result.vv); // vv is virtuals.

the mongooseLeanDefaults plugin can auto lean, but mongooseLeanVirtuals cannot.

i hope mongooseLeanVirtuals can esay use just like use mongooseLeanDefaults .

minefujiko9293 avatar Feb 22 '24 04:02 minefujiko9293

Okay, it turns out that the NPM package is not synchronized with the git warehouse. please republish the npm mongoose-lean-virtuals.

minefujiko9293 avatar Feb 22 '24 05:02 minefujiko9293