Skip to content

Gary-Osteen-Q2/mongoose-lean-methods

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mongoose-lean-methods

Attach methods to the results of mongoose queries when using .lean(). Highly inspired by mongoose-lean-virtuals and mongoose-lean-defaults.
Note: schema.methods attaching affect to slow performance when find documents, avoid create much methods in schema is better.

Install

npm install --save mongoose-lean-methods

or

yarn add mongoose-lean-methods

Usage

const mongooseLeanMethods = require('mongoose-lean-methods')

const schema = new mongoose.Schema({
  name: String,
})

schema.methods.showName = async function() {
  console.log(this.name)
}
// or
schema.method('showName', async function(){
  console.log(this.name)
})

schema.plugin(mongooseLeanMethods)

// You must pass `methods: true` to `.lean()`
const doc = await Model.findOne().lean({ methods: true })
doc.showname()

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%