# mongoose-property-filter-plugin

> Mongoose plugin to easily remove desired properties from the the schema object.

Latest version **1.6.0** (published 2017-06-16) · GPL-3.0 license · 0 weekly downloads

## Install

```sh
npm install mongoose-property-filter-plugin
pnpm add mongoose-property-filter-plugin
yarn add mongoose-property-filter-plugin
bun add mongoose-property-filter-plugin
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.6.0 |
| Published | 2017-06-16 |
| First published | 2017-05-21 |
| Weekly downloads | 0 |
| License | GPL-3.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=6 |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | João Miguel |
| Maintainers | jmtvms |
| Keywords | mongoose, schema, property, filter, model, plugin |

## Links

- npm: https://www.npmjs.com/package/mongoose-property-filter-plugin
- Repository: https://github.com/jmtvms/mongoose-property-filter-plugin
- Issues: https://github.com/jmtvms/mongoose-property-filter-plugin/issues
- npm.io page: https://npm.io/package/mongoose-property-filter-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

- 1.6.0 (latest) — 2017-06-16
- 1.5.1 — 2017-06-16
- 1.5.0 — 2017-06-08
- 1.2.3 — 2017-05-22
- 1.2.103 — 2017-05-22
- 1.2.101 — 2017-05-22
- 1.0.100 — 2017-05-22
- 1.2.0 — 2017-05-22
- 1.1.3 — 2017-05-21
- 1.1.2 — 2017-05-21
- 1.1.1 — 2017-05-21

## README

# mongoose-property-filter-plugin
[![npm](https://img.shields.io/npm/v/mongoose-property-filter-plugin.svg?style=flat-square)](https://www.npmjs.com/package/mongoose-property-filter-plugin)
[![Travis](https://img.shields.io/travis/jmtvms/mongoose-property-filter-plugin.svg?style=flat-square)](https://travis-ci.org/jmtvms/mongoose-property-filter-plugin)
[![npm](https://img.shields.io/npm/dt/mongoose-property-filter-plugin.svg?style=flat-square)](https://www.npmjs.com/package/mongoose-property-filter-plugin)  
Mongoose plugin to easly remove properties from the schema without removing any data.

## How to use it
To use this module just add the reference to you javascript file.

```javascript
const mongoosePropertyFilter = require('mongoose-property-filter');
```

Then just add the plugin on the shcema app.

```javascript
const clientSchema = new Schema({
    name: {
        type: String,
        required: [true, 'Client name is mandatory']
    }
});

clientSchema.plugin(mongoosePropertyFilter);
```

## Configuring

You can configure the toJSON and toObject methods output properties filter from your schema using regex ``` /(_|deleted|created|updated).*/ ```, a whitespace separed string ``` "_id __v createdAt updatedAt deleted deletedAt deletedBy" ``` or even an array of strings ``` ["_id", "__v", "createdAt", "updatedAt", "deleted", "deletedAt, "deletedBy"] ```.

### Options available and their default values

|    Property   |            Type           |             Default             |                                                                         Description                                                                        |
|:-------------:|:-------------------------:|:-------------------------------:|:----------------------------------------------------------------------------------------------------------------------------------------------------------:|
| **hide**          | Regexp, String, [String] | /(_\|deleted\|created\|updated).\*/ | Fields to be removed from the schema. |
| **showVirtuals**  |            Bool           |               false              | Force virtual fields to be shown.      
| **showGetters**  |            Bool           |               false              | Force getters fields to be shown.                                                                                                                       |
| **versionKey**    |            Bool           |              false              | Show the version key from the schema.                                                                                                                      |
| **_id**           |            Bool           |              false              | Show the _id field from the schema.                                                                                                                        |
| **allLevels**     |            Bool           |              true               | All nestes schemas are filtered too.                                                                                                                        |
| **applyToJSON**   |            Bool           |               true              | Should the filters be applied on the toJSON method from the schema.                                                                                        |
| **applyToObject** |            Bool           |              false              | Should the filters be applied on the toObject method from the schema.                                                                                      |
### Using the options on your schema



```javascript
const clientSchema = new Schema({
    name: {
        type: String,
        required: [true, 'Client name is mandatory']
    },
    myCustomField: {
        type: String,
    }
});

// With this options the JSON version of this schema will be { "name" : "Wally" }
const opt = { "hide" : "myCustomField" };
clientSchema.plugin(mongoosePropertyFilter, opt);
```

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