mongoose-lean-getters
TypeScript icon, indicating that this package has built-in type declarations

2.1.0 • Public • Published

mongoose-lean-getters

Apply getters on lean() documents: https://mongoosejs.com/docs/tutorials/lean.html

This package requires Mongoose >= 7.1.0. Do not use with Mongoose 7.0.x or 6.x.

Usage

const mongoose = require('mongoose');
const mongooseLeanGetters = require('mongoose-lean-getters');

const schema = mongoose.Schema({
  name: {
    type: String,
    // Get the last 6 characters of the string
    get: v => v.slice(-6)
  }
});
// Add this plugin to apply getters when using `lean()`.
schema.plugin(mongooseLeanGetters);

await Model.create({ name: 'Captain Jean-Luc Picard' });

const doc = await Model.findOne().lean({ getters: true });
doc.name; // 'Picard'

Package Sidebar

Install

npm i mongoose-lean-getters

Weekly Downloads

8,946

Version

2.1.0

License

Apache 2.0

Unpacked Size

36.4 kB

Total Files

14

Last publish

Collaborators

  • vkarpov15