mongoose-json-select
A mongoose plugin to limit JSON properties and set the unselected fields to null.
var jsonSelect = ; var schema = ;schema;var User = mongoose; var user = ;JSON;// -> '{"name": "alice", "email": null , "created": "2013-03-16T16:08:38.065Z"}' JSON;// -> '{"name": "alice", "email": "alice@example.com", "created": null }'
Installation
$ npm install k-mongoose-json-select
Usage
Inclusion/Exclusion
// inclusion. these are equivalentschema;schema; // exclusion. these are equivalentschema;schema;
Always exclude _id,id and __v field if the field is not included explicitly.
schema; // contains 'name' only
Configures default fields as a plugin option or schema option.
// these are equivalentschema; schema;schema;
Specifies fields when calling toJSON.
// this overrides a default configurationJSON;
The syntax for fields is the same with mongoose's Query#select.
http://mongoosejs.com/docs/api.html#query_Query-select
Support
This plugin is proudly supported by Kubide desarrollo@kubide.es
License
MIT