# mongoose-merge-plugin

> Merge plugin for mongoose documents

Latest version **0.0.5** (published 2014-12-13) · 0 weekly downloads

## Install

```sh
npm install mongoose-merge-plugin
pnpm add mongoose-merge-plugin
yarn add mongoose-merge-plugin
bun add mongoose-merge-plugin
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.5 |
| Published | 2014-12-13 |
| First published | 2013-07-15 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 0.8.1 |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 14 |
| Author | Eric Herve |
| Maintainers | eherve |
| Keywords | mongoose |

## Links

- npm: https://www.npmjs.com/package/mongoose-merge-plugin
- Repository: https://github.com/eherve/mongoose-merge-plugin
- Issues: https://github.com/eherve/mongoose-merge-plugin/issues
- npm.io page: https://npm.io/package/mongoose-merge-plugin

## 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
- [@temporal-architect/claude-plugin](https://npm.io/package/@temporal-architect/claude-plugin.md) — 335 weekly downloads

## Recent versions

- 0.0.5 (latest) — 2014-12-13
- 0.0.4 — 2014-03-13
- 0.0.3 — 2013-10-02
- 0.0.2 — 2013-07-18
- 0.0.1 — 2013-07-15

## README

# mongoose-merge-plugin

Mongoose plugin for document merging

## Install npm install mongoose-merge-plugin

## Loading

  var merge = require('mongoose-merge-plugin');

## Inintialization

  var mongoose = require('mongoose');
  
  mongoose.plugin(merge);

## Usage

The method <i>merge</i> is added to all mongoose documents. It takes a source object as parameter and merge it in the target existing documents. It checks for existing values in the source object regarding the field path of the destination document.
It does not merge the <i>\_id</i> and <i>\_\_v</i> default fields and check for the schema field option <i>mergeable</i>. If the option is false, the merge skip the field as well.

The method <i>merge</i> accept a second parameter that is the merge options. this parameter allow to specify a filter on fields when calling the merge.

* <b>options.fields</b>

> It is a string with field names, separeted by one or more spaces. If the field path is present in this string, the merge check if the mongoose field is mergeable and if yes it allows the merge. If before the field path a + flag is added, then the field will be merged (overriding the schema field option). If the flag is '-' the field will not be merged as well as if the field name is not present.

* <b>options.virtuals</b>

> It is a boolean value that activates the merging of the virtuals fields

## Example

<pre>
var mongoose = require('mongoose'),
    Schema = mongoose.Schema;
var schema = new Schema({
  name: String,
  description: String,
  notMergedField: { type: String, mergeable: false }
});
var Test = mongoose.model('Test', schema);
var test = new Test({ name: "test", description: "desc", notMergedField: "testNMF" });
console.log(test); // LOG: { i_id: ..., name: test, description: desc, notMergedField: testNMF ...}
test.merge({ name: "testChanged", description: "descChanged", notMergedField: "testNMFChanged" });
console.log(test); // LOG: { i_id: ..., name: testChanged, description: descChanged, notMergedField: testNMF ...}
test.merge({ name: "test", description: "desc" }, { fields: "-description" });
console.log(test); // LOG: { i_id: ..., name: test, description: descChanged, notMergedField: testNMF ...}
</pre>

## Support

<a href="http://www.it-tweaks.com/" target="_blank">it-tweaks</a>

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