# mongoose-lean-id

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

Latest version **1.1.0** (published 2025-12-05) · Apache 2.0 license · 0 weekly downloads

## Install

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

## Health

**Score 53/100 (C)** — status: stable.

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2025-12-05 |
| First published | 2017-01-08 |
| Weekly downloads | 0 |
| License | Apache 2.0 |
| TypeScript types | separate (@types/mongoose-lean-id) |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 23 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 24 |
| Author | Valeri Karpov |
| Maintainers | vkarpov15 |
| Keywords | mongoose, lean, id, mongodb |

## Links

- npm: https://www.npmjs.com/package/mongoose-lean-id
- Repository: https://github.com/vkarpov15/mongoose-lean-id
- Issues: https://github.com/vkarpov15/mongoose-lean-id/issues
- npm.io page: https://npm.io/package/mongoose-lean-id

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 1.1.0 (latest) — 2025-12-05
- 1.0.0 — 2023-12-01
- 0.5.0 — 2023-03-23
- 0.4.0 — 2023-03-21
- 0.3.0 — 2022-01-08
- 0.2.0 — 2019-02-25
- 0.1.1 — 2018-11-10
- 0.1.0 — 2017-05-20
- 0.0.1 — 2017-01-08

## README

# mongoose-lean-id

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

## Usage

```javascript
const mongooseLeanId = require('mongoose-lean-id');
```


# examples

## It attaches `.id` to result of find, findOne, and findOneAndUpdate if lean

```javascript

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

    schema.plugin(mongooseLeanId);

    const Model = mongoose.model('Test', schema);

    return Model.create({ name: 'test' }).
      then(() => Promise.all([
        Model.find().lean(),
        Model.findOne().lean(),
        Model.findOneAndUpdate({}, { name: 'test' }).lean()
      ])).
      then(results => {
        const [findRes, findOneRes, findOneAndUpdateRes] = results;
        assert.equal(findRes[0].id, findRes[0]._id.toHexString());
        assert.equal(findOneRes.id, findOneRes._id.toHexString());
        assert.equal(findOneAndUpdateRes.id,
          findOneAndUpdateRes._id.toHexString());
      });
  
```

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