mongoose-lean-virtuals
mongoose-lean-virtuals copied to clipboard
how to set lean default with typegoose
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 .
Okay, it turns out that the NPM package is not synchronized with the git warehouse. please republish the npm mongoose-lean-virtuals.