# mongoose-mass-assign

> A mongoose plugin to help safely perform mass assignments from web input

Latest version **0.4.0** (published 2013-11-10) · 0 weekly downloads

## Install

```sh
npm install mongoose-mass-assign
pnpm add mongoose-mass-assign
yarn add mongoose-mass-assign
bun add mongoose-mass-assign
```

## 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.4.0 |
| Published | 2013-11-10 |
| First published | 2012-11-30 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 (+8 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 11 |
| Author | Benjamin Eckel |
| Maintainers | bhelx |

## Links

- npm: https://www.npmjs.com/package/mongoose-mass-assign
- Repository: https://github.com/bhelx/mongoose-mass-assignment
- Issues: https://github.com/bhelx/mongoose-mass-assignment/issues
- npm.io page: https://npm.io/package/mongoose-mass-assign

## Dependencies (1)

- [mongoose](https://npm.io/package/mongoose.md) 3.x.x

## Recent versions

- 0.4.0 (latest) — 2013-11-10
- 0.3.0 — 2012-12-09
- 0.2.3 — 2012-11-30
- 0.2.2 — 2012-11-30
- 0.2.1 — 2012-11-30
- 0.2.0 — 2012-11-30

## README

## mongoose-mass-assign

This plugin provides two functions called #massAssign to your models. One static and one instance. You can use these to protect specific fields from web input. The plugin adds the schematype option 'protect' so you don't have to write any filtering code.

You can also get direct access to the filtering mechanism through the static massUpdate.

## Install

```
npm install mongoose-mass-assign
```

Current version 0.3.0

## Usage

Defining:

```js
var massAssign = require('mongoose-mass-assign');

var UserSchema = new mongoose.Schema({
  name      : String,
  admin     : { type: Boolean, protect: true, default: false },
  verified  : { type: Boolean, protect: true, default: false }
});

UserSchema.plugin(massAssign);

var User = mongoose.model('User', UserSchema);

```

Using:

```js

/** Static method, useful for creation **/

var user = User.massAssign({
  name: 'bhelx',
  admin: true
});

// user => { name: 'bhelx', admin: false, verified: false }

/** Instance method, useful for updating  **/
var user = new User;

user.massAssign({
  name: 'bhelx',
  admin: true
});

// user => { name: 'bhelx', admin: false, verified: false }

/** Static massUpdate method **/
var input = { name: 'bhelx', admin: 'true' };

User.update({ '_id': someId }, { $set: User.massUpdate(input) }, console.log);

```
For more details see test.js

## Testing

```
npm install
```

```
make test
```

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