mongoose-json-select
A mongoose plugin to limit JSON properties.
var jsonSelect = ; var schema = ;schema;var User = mongoose; var user = ;JSON;// -> '{"_id": "51466baedf03a52e9b000001", "name": "alice", "created": "2013-03-16T16:08:38.065Z"}' JSON;// -> '{"_id": "51466baedf03a52e9b000001", "name": "alice", "email": "alice@example.com"}'
Installation
$ npm install mongoose-json-select
Usage
Inclusion/Exclusion
// inclusion. these are equivalentschema;schema; // exclusion. these are equivalentschema;schema;
Always includes _id field if the field is not excluded explicitly.
schema; // contains 'name' and '_id'
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
Documentation
select(obj, fields)
Creates a deep clone of 'obj' filtered by 'fields'.
var select = select;;// -> {a: {b: 'foo'}}
License
MIT