# mongoose-autopopulate

> Always populate() certain fields in your mongoose schemas

Latest version **1.2.1** (published 2025-11-19) · Apache 2.0 license · 0 weekly downloads

## Install

```sh
npm install mongoose-autopopulate
pnpm add mongoose-autopopulate
yarn add mongoose-autopopulate
bun add mongoose-autopopulate
```

## Health

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

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

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 1.2.1 |
| Published | 2025-11-19 |
| First published | 2015-02-26 |
| Weekly downloads | 0 |
| License | Apache 2.0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 37.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Valeri Karpov |
| Maintainers | vkarpov15 |
| Keywords | mongoose, populate, autopopulate, mongodb |

## Links

- npm: https://www.npmjs.com/package/mongoose-autopopulate
- Repository: https://github.com/mongoosejs/mongoose-autopopulate
- Issues: https://github.com/mongoosejs/mongoose-autopopulate/issues
- npm.io page: https://npm.io/package/mongoose-autopopulate

## 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

- 1.2.1 (latest) — 2025-11-19
- 1.0.0-rc0 (next) — 2023-02-24
- 1.2.0 — 2025-11-19
- 1.1.0 — 2023-10-24
- 1.0.1 — 2023-05-05
- 1.0.0 — 2023-02-27
- 0.17.1 — 2023-01-03
- 0.17.0 — 2022-12-29
- 0.16.1 — 2022-04-04
- 0.16.0 — 2021-09-22
- 0.15.0 — 2021-09-06
- 0.14.0 — 2021-05-14
- 0.13.0 — 2021-04-16
- 0.12.3 — 2020-11-08
- 0.12.2 — 2020-04-19
- … 17 more at https://npm.io/package/mongoose-autopopulate/versions

## README

# mongoose-autopopulate

Always `populate()` certain fields in your mongoose schemas

[![Build Status](https://travis-ci.org/mongodb-js/mongoose-autopopulate.svg?branch=master)](https://travis-ci.org/mongodb-js/mongoose-autopopulate)
[![Coverage Status](https://coveralls.io/repos/mongodb-js/mongoose-autopopulate/badge.svg?branch=master)](https://coveralls.io/r/mongodb-js/mongoose-autopopulate?branch=master)

[Read the docs here](http://plugins.mongoosejs.io/plugins/autopopulate).

**Note:** population is a powerful feature, but it has limitations and
helps you get away with poor schema design.  In particular, it is usually
bad MongoDB schema design to include arrays that grow without bound in
your documents. Do not include a constantly-growing array of ObjectIds
in your schema - your data will become unwieldy as the array grows and
you will eventually hit the [16 MB document size limit](http://docs.mongodb.org/manual/reference/limits/#BSON-Document-Size).
In general, think carefully when designing your schemas.

# Usage

The `mongoose-autopopulate` module exposes a single function that you can
pass to [Mongoose schema's `plugin()` function](https://mongoosejs.com/docs/api.html#schema_Schema-plugin).

```javascript
const schema = new mongoose.Schema({
  populatedField: {
    type: mongoose.Schema.Types.ObjectId,
    ref: 'ForeignModel',
    // The below option tells this plugin to always call `populate()` on
    // `populatedField`
    autopopulate: true
  }
});
schema.plugin(require('mongoose-autopopulate'));
```

Only apply this plugin to top-level schemas. Don't apply this plugin to child schemas.

```javascript
// Don't do `nestedSchema.plugin(require('mongoose-autopopulate'))`.
// You only need to add mongoose-autopopulate to top-level schemas.
const nestedSchema = mongoose.Schema({
  child: { type: Number, ref: 'Child', autopopulate: true }
});
const topSchema = mongoose.Schema({ nested: nestedSchema });
topSchema.plugin(require('mongoose-autopopulate'));
```

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