Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mongoose-lean-defaults

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongoose-lean-defaults

Attach defaults to the results of mongoose queries when using `.lean()`

  • 2.2.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
19K
decreased by-8.82%
Maintainers
1
Weekly downloads
 
Created
Source

mongoose-lean-defaults

Attach defaults to the results of mongoose queries when using .lean(). Highly inspired by mongoose-lean-virtuals.

Run Tests Node.js Package

Install

npm install --save mongoose-lean-defaults

or

yarn add mongoose-lean-defaults

Usage

import mongooseLeanDefaults from 'mongoose-lean-defaults';
// const mongooseLeanDefaults = require('mongoose-lean-defaults').default;

const userSchema = new mongoose.Schema({
  name: {
    type: String,
    default: 'Bob',
  },
});
// documents will only have `name` field on database

// Later
const updatedUserSchema = new mongoose.Schema({
  name: {
    type: String,
    default: 'Bob',
  },
  country: {
    type: String,
    default: 'USA',
  },
});
// `.find().lean()` will return documents without `country` field

updatedUserSchema.plugin(mongooseLeanDefaults);

// You must pass `defaults: true` to `.lean()`
const bob = await UserModel.findOne().lean({ defaults: true });
/**
 * bob = {
 *    _id: ...,
 *    name: 'Bob',
 *    country: 'USA'
 * }
 */

Keywords

FAQs

Package last updated on 25 Jun 2022

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