# mongoose-lean-methods

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

Latest version **0.1.1** (published 2020-05-05) · ISC license · 0 weekly downloads

## Install

```sh
npm install mongoose-lean-methods
pnpm add mongoose-lean-methods
yarn add mongoose-lean-methods
bun add mongoose-lean-methods
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.1 |
| Published | 2020-05-05 |
| First published | 2020-05-05 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 11.6 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | teradonburi |
| Maintainers | teradonburi |
| Keywords | mongodb, mongoose, lean, methods |

## Links

- npm: https://www.npmjs.com/package/mongoose-lean-methods
- Repository: https://github.com/teradonburi/mongoose-lean-methods
- Homepage: https://github.com/teradonburi/mongoose-lean-methods#readme
- Issues: https://github.com/teradonburi/mongoose-lean-methods/issues
- npm.io page: https://npm.io/package/mongoose-lean-methods

## Dependencies (1)

- [mpath](https://npm.io/package/mpath.md) ^0.7.0

## Alternatives

- [angular-pipes](https://npm.io/package/angular-pipes.md) — 5.6K weekly downloads
- [@ng-web-apis/midi](https://npm.io/package/@ng-web-apis/midi.md) — 2.6K weekly downloads
- [happn-3](https://npm.io/package/happn-3.md) — 1.6K weekly downloads
- [@opensip-cli/lang-go](https://npm.io/package/@opensip-cli/lang-go.md) — 1.2K weekly downloads
- [mongoose-typescript](https://npm.io/package/mongoose-typescript.md) — 85 weekly downloads

## Recent versions

- 0.1.1 (latest) — 2020-05-05
- 0.1.0 — 2020-05-05

## README

# 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()
```

---
_Source: https://npm.io/package/mongoose-lean-methods · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
