Package Exports
- @meanie/mongoose-upsert-many
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@meanie/mongoose-upsert-many) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
@meanie/mongoose-upsert-many
A plugin that adds an upsertMany bulk op to Mongoose schemas

Installation
You can install this package using yarn or npm.
#yarn
yarn add @meanie/mongoose-upsert-many
#npm
npm install @meanie/mongoose-upsert-many --saveUsage
Setup as a global plugin for all Mongoose schema's:
const mongoose = require('mongoose');
const upsertMany = require('@meanie/mongoose-upsert-many');
mongoose.plugin(upsertMany);Or for a specific (sub) schema:
const mongoose = require('mongoose');
const upsertMany = require('@meanie/mongoose-upsert-many');
const {Schema} = mongoose;
const MySchema = new Schema({});
MySchema.plugin(upsertMany);This plugin will expose a static upsertMany method on your models which you
can use to perform bulk upsert operations:
//Large amount of items
const items = [
...
];
//Fields to match on for upsert condition
const matchFields = ['foo', 'bar.nested'];
//Perform bulk operation
const result = MyModel.upsertMany(items, matchFields);
//Returns MongoDB bulk result object
console.log(result.nUpserted + result.nModified, 'items processed');Items you pass in can be mongoose Models or raw data, but they are always converted to Mongoose models to ensure schema validation is applied, and then converted back to plain, depopulated objects for safe insertion with the bulk operation.
Match fields are fields that are used as match criteria for the upsert operations,
e.g. in the find() portion of the bulk op. You can also provide default match
fields for the whole schema using the option upsertMatchFields when defining your schema.
Issues & feature requests
Please report any bugs, issues, suggestions and feature requests in the @meanie/mongoose-upsert-many issue tracker.
Contributing
Pull requests are welcome! If you would like to contribute to Meanie, please check out the Meanie contributing guidelines.
Credits
- Meanie logo designed by Quan-Lin Sim
License
(MIT License)
Copyright 2018, Adam Reis