1.5.0 • Published 9 years ago

mongoose-model-update v1.5.0

Weekly downloads
1
License
MIT
Repository
github
Last release
9 years ago

Mongoose Model Update

NPM

Mongoose plugin providing a Model method for simple, filtered patch-style updates

Setup

Install

npm install --save mongoose-model-update

Require this alongside your router-

import update from 'mongoose-model-update';
// Or, for ES5-
// var update = require('mongoose-model-update');

Usage

When registering the Mongoose plugin, you can optionally specify allowed fields at the Model-level to be used as default params in Model.methods.update().

Model.plugin(update, ['name', 'bday', 'city']);

You can specify permitted fields to update in the 2nd argument. If no fields are provided and default params aren't set at the Model-level, then all fields will be available to update.

user.update(source, ['age'])

Use cases

At AutoLotto, we use this for PATCH API updates (RESTfully speaking). Ex-

export async function update(req, res) {
  // ...
  req.user.update(req.body);
  // ...
}
1.5.0

9 years ago

1.4.0

9 years ago

1.3.1

9 years ago

1.3.0

9 years ago

1.2.0

9 years ago

1.1.3

9 years ago

1.1.2

9 years ago

1.1.1

9 years ago

1.1.0

9 years ago

1.0.0

9 years ago