Package Exports
- mongoose-lean-virtuals
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (mongoose-lean-virtuals) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
mongoose-lean-virtuals
Attach virtuals to the results of mongoose queries when using .lean().
Usage
const mongooseLeanVirtuals = require('mongoose-lean-virtuals');
// Example schema
const userSchema = new mongoose.Schema({ name: String });
userSchema.virtual('lowercase').get(function() {
return this.name.toLowerCase();
});
// Now, the `lowercase` property will show up even if you do a lean query
userSchema.plugin(mongooseLeanVirtuals);
// Later
// You **must** pass `virtuals: true` to `lean()`, otherwise `lowercase`
// won't be in `res`
const res = await UserModel.find().lean({ virtuals: true });