# mongoose-field-populate

Latest version **2.2.10** (published 2021-02-07) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install mongoose-field-populate
pnpm add mongoose-field-populate
yarn add mongoose-field-populate
bun add mongoose-field-populate
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 2.2.10 |
| Published | 2021-02-07 |
| First published | 2019-11-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 6 |
| Unpacked size | 46.1 KB |
| Known vulnerabilities | 0 (+4 in 2 direct dependencies) |
| Install scripts | no |
| Maintainers | 3merge |

## Links

- npm: https://www.npmjs.com/package/mongoose-field-populate
- npm.io page: https://npm.io/package/mongoose-field-populate

## Dependencies (6)

- [flat](https://npm.io/package/flat.md) ^5.0.0
- [mongoose](https://npm.io/package/mongoose.md) ^5.7.12
- [cachegoose](https://npm.io/package/cachegoose.md) ^8.0.0
- [lodash.get](https://npm.io/package/lodash.get.md) ^4.4.2
- [lodash.set](https://npm.io/package/lodash.set.md) ^4.3.2
- [lodash.unset](https://npm.io/package/lodash.unset.md) ^4.5.2

## Recent versions

- 2.2.10 (latest) — 2021-02-07
- 2.2.9 — 2021-02-05
- 2.2.8 — 2021-02-05
- 2.2.7 — 2021-02-05
- 2.2.6 — 2020-08-07
- 2.2.5 — 2020-08-04
- 2.2.4 — 2020-08-03
- 2.2.3 — 2020-07-21
- 2.2.2 — 2020-07-21
- 2.2.1 — 2020-06-26
- 2.2.0 — 2020-06-26
- 2.1.7 — 2020-06-09
- 2.1.6 — 2020-06-09
- 2.1.5 — 2020-06-09
- 2.1.4 — 2020-06-09
- … 9 more at https://npm.io/package/mongoose-field-populate/versions

## README

<h1>💫 Mongoose Extended Reference and Autopopulate</h1>
<p>
  <img src="https://github.com/MikeIbberson/mongoose-field-populate/workflows/Node%20CI/badge.svg" alt="Status" />
<a href='https://coveralls.io/github/MikeIbberson/mongoose-field-populate?branch=master'><img src='https://coveralls.io/repos/github/MikeIbberson/mongoose-field-populate/badge.svg?branch=master' alt='Coverage Status' /></a>
<img src='https://bettercodehub.com/edge/badge/MikeIbberson/mongoose-field-populate?branch=master'>
</p> 

<h2>Extended Reference</h2>

<p>The extended reference builder provides a plugin for managing stale data updating as well as a builder for assembling extended references. It auto-syncs the target props on save, so you don't have to worry about matching types, setting projects and more.</p>

``` Javascript
  const mongoose = require('mongoose');
  const { ExtendedReference } = require('mongoose-field-populate');

  const ReferenceSchema = new mongoose.Schema({
    name: String,
    age: Number,
  });

  ReferenceSchema.plugin(ExtendedReference.plugin, [
    'TARGETS',
  ]);

  module.exports = mongoose.model('DEMO_ONLY', ReferenceSchema);
```

``` Javascript
  const mongoose = require('mongoose');
  const { ExtendedReference } = require('mongoose-field-populate');
  const ReferenceModel = require('./reference');

  const TargetSchema = new mongoose.Schema({
    friend: new ExtendedReference(ReferenceModel)
      .on(['name', 'age'])
      .set('name', { private: true })
      .done(),
  });

  module.exports = mongoose.model('TARGETS', TargetSchema);
```

<h2>Autopopulate</h2>

<p>This package also ships with a very basic autopopulation feature. The most common solution on NPM does not suit my needs, though it might fit nicely into your project. Use this only if you require autopopulation on discriminators or embedded arrays.</p>

``` Javascript
  const mongoose = require('mongoose');
  const { autopopulate } = require('mongoose-field-populate');
  
  const TargetSchema = new mongoose.Schema({
    email: {
      type: String,
      unique: true,
      autopopulate: true,
      autopopulateSelect: 'projection path',
    }
  });

  TargetSchema.plugin(autopopulate)
```

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