Array of common fields to emit for Mongoose toObject/toJSON (helpful for security)
npm install mongoose-omit-common-fields





> Array of common fields to emit for Mongoose toObject/toJSON (helpful for security)
* Install
* Usage
* Reference
* API
* omitCommonFields.underscored.keys
* omitCommonFields.underscored.str
* omitCommonFields.underscored.obj
* omitCommonFields.underscored.objTrue
* omitCommonFields.camelCased.keys
* omitCommonFields.camelCased.str
* omitCommonFields.camelCased.obj
* omitCommonFields.camelCased.objTrue
* Tips
* Contributors
* License
[npm][]:
``sh`
npm install mongoose-omit-common-fields
[yarn][]:
`sh`
yarn add mongoose-omit-common-fields
`js
const mongoose = require('mongoose');
const mongooseHidden = require('mongoose-hidden')();
const omitCommonFields = require('mongoose-omit-common-fields');
const Schema = new mongoose.Schema();
Schema.plugin(
mongooseHidden,
// if your database fields are camelCased then
// you will need to use omitCommonFields.camelCased variationomitCommonFields.camelCased.objTrue
// (e.g. )`
{ hidden: omitCommonFields.underscored.objTrue }
);
If you want to add additional keys to be omitted:
`js`
Schema.plugin(
mongooseHidden,
{
hidden: {
...omitCommonFields.underscored.objTrue,
some_other_field: true,
another_field_to_ignore: true
}
}
);
For more information on - and object notation, please see
`js`
[ '_id',
'__v',
'ip',
'last_ips',
'email',
'api_token',
'group',
'attempts',
'last',
'hash',
'password',
'salt',
'reset_token_expires_at',
'reset_token',
'google_profile_id',
'google_access_token',
'google_refresh_token' ]
`js`
"-_id -__v -ip -last_ips -email -api_token -group -attempts -last -hash -password -salt -reset_token_expires_at -reset_token -google_profile_id -google_access_token -google_refresh_token"
`js`
{ _id: 0,
__v: 0,
ip: 0,
last_ips: 0,
email: 0,
api_token: 0,
group: 0,
attempts: 0,
last: 0,
hash: 0,
password: 0,
salt: 0,
reset_token_expires_at: 0,
reset_token: 0,
google_profile_id: 0,
google_access_token: 0,
google_refresh_token: 0 }
`js`
{ _id: true,
__v: true,
ip: true,
last_ips: true,
email: true,
api_token: true,
group: true,
attempts: true,
last: true,
hash: true,
password: true,
salt: true,
reset_token_expires_at: true,
reset_token: true,
google_profile_id: true,
google_access_token: true,
google_refresh_token: true }
`js`
[ 'id',
'v',
'ip',
'lastIps',
'email',
'apiToken',
'group',
'attempts',
'last',
'hash',
'password',
'salt',
'resetTokenExpiresAt',
'resetToken',
'googleProfileId',
'googleAccessToken',
'googleRefreshToken' ]
`js`
"-id -v -ip -lastIps -email -apiToken -group -attempts -last -hash -password -salt -resetTokenExpiresAt -resetToken -googleProfileId -googleAccessToken -googleRefreshToken"
`js`
{ id: 0,
v: 0,
ip: 0,
lastIps: 0,
email: 0,
apiToken: 0,
group: 0,
attempts: 0,
last: 0,
hash: 0,
password: 0,
salt: 0,
resetTokenExpiresAt: 0,
resetToken: 0,
googleProfileId: 0,
googleAccessToken: 0,
googleRefreshToken: 0 }
`js``
{ id: true,
v: true,
ip: true,
lastIps: true,
email: true,
apiToken: true,
group: true,
attempts: true,
last: true,
hash: true,
password: true,
salt: true,
resetTokenExpiresAt: true,
resetToken: true,
googleProfileId: true,
googleAccessToken: true,
googleRefreshToken: true }
Note that this package is already built-in to [mongoose-common-plugin][].
| Name | Website |
| -------------- | -------------------------- |
| Nick Baugh |
##
[npm]: https://www.npmjs.com/
[yarn]: https://yarnpkg.com/
[mongoose-common-plugin]: https://github.com/ladjs/mongoose-common-plugin