npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mongoose-property-filter-plugin

v1.6.0

Published

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

Downloads

35

Readme

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

| 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

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