New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

mongoose-lean-getters

Package Overview
Dependencies
Maintainers
0
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongoose-lean-getters

Apply getters to the results of mongoose queries when using `.lean()`

  • 2.2.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
23K
decreased by-19.59%
Maintainers
0
Weekly downloads
 
Created
Source

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'

You may also set the default lean options to always use getters:

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)
  }
});
// Set the default options for all lean queries
schema.plugin(mongooseLeanGetters, { defaultLeanOptions: { getters: true }});

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

const doc = await Model.findOne().lean();
doc.name; // 'Picard'

// You may also set getters: false at call time
const doc2 = await Model.findOne().lean({ getters: false });
doc2.name; // 'Captain Jean-Luc Picard'

Keywords

FAQs

Package last updated on 24 Feb 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc