mblarsen / mongoose-hidden

A Mongoose schema plugin for filtering properties you usually do not want to sent client-side like passwords and IDs.
MIT License
89 stars 19 forks source link

Add `hidden` option #11

Closed bisubus closed 7 years ago

bisubus commented 7 years ago

The suggestion is to introduce hidden option in addition to defaultHidden.

defaultHidden option overrides previously defined defaults. This may not be always desired, because it requires to redefine hidden properties that could be otherwise inherited from default configuration.

From my own experience, the models may show _id or hide timestamps, but __v never needs to be exposed, so it is just redundant to mention it every time.

It would be generally easier to manage hidden properties in additive manner (Object.assign),

schema.plugin(mongooseHidden, { hidden: { _id: false, createdAt: true, updatedAt: true });
mblarsen commented 7 years ago

Good idea. I've implemented the feature and added/adjusted test cases. Could you try it out? Then I'll merge and publish to npm.

https://github.com/mblarsen/mongoose-hidden/tree/feature-hidden

bisubus commented 7 years ago

Thanks for the quick response, works like a charm! Stumbled across a couple of issues on the way.

mblarsen commented 7 years ago

Merged and published