1.6.0 • Published 7 years ago

mongoose-property-filter-plugin v1.6.0

Weekly downloads
1
License
GPL-3.0
Repository
github
Last release
7 years ago

mongoose-property-filter-plugin

npm Travis npm
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.

const mongoosePropertyFilter = require('mongoose-property-filter');

Then just add the plugin on the shcema app.

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

PropertyTypeDefaultDescription
hideRegexp, String, String/(_|deleted|created|updated).*/Fields to be removed from the schema.
showVirtualsBoolfalseForce virtual fields to be shown.
showGettersBoolfalseForce getters fields to be shown.
versionKeyBoolfalseShow the version key from the schema.
_idBoolfalseShow the _id field from the schema.
allLevelsBooltrueAll nestes schemas are filtered too.
applyToJSONBooltrueShould the filters be applied on the toJSON method from the schema.
applyToObjectBoolfalseShould the filters be applied on the toObject method from the schema.

Using the options on your schema

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);
1.6.0

7 years ago

1.5.1

7 years ago

1.5.0

7 years ago

1.2.3

7 years ago

1.2.103

7 years ago

1.2.101

7 years ago

1.0.100

7 years ago

1.2.0

7 years ago

1.1.3

7 years ago

1.1.2

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago