
Product
Introducing Scala and Kotlin Support in Socket
Socket now supports Scala and Kotlin, bringing AI-powered threat detection to JVM projects with easy manifest generation and fast, accurate scans.
k-mongoose-json-select
Advanced tools
A mongoose plugin to limit JSON properties and set this properties to null.
A mongoose plugin to limit JSON properties and set the unselected fields to null.
var jsonSelect = require('k-mongoose-json-select');
var schema = Schema({
name: String,
email: String,
created: {type: Date, default: Date.now}
});
schema.plugin(jsonSelect, 'name created');
var User = mongoose.model('User', schema);
var user = User({name: 'alice', email: 'alice@example.com'});
JSON.stringify(user);
// -> '{"name": "alice", "email": null , "created": "2013-03-16T16:08:38.065Z"}'
JSON.stringify(user.toJSON({select: 'name email'}));
// -> '{"name": "alice", "email": "alice@example.com", "created": null }'
$ npm install k-mongoose-json-select
Inclusion/Exclusion
// inclusion. these are equivalent
schema.plugin(jsonSelect, 'name.first');
schema.plugin(jsonSelect, {'name.first': 1});
// exclusion. these are equivalent
schema.plugin(jsonSelect, '-name.last');
schema.plugin(jsonSelect, {'name.last': 0});
Always exclude _id,id and __v field if the field is not included explicitly.
schema.plugin(jsonSelect, 'name'); // contains 'name' only
Configures default fields as a plugin option or schema option.
// these are equivalent
schema.plugin(jsonSelect, 'name');
schema.plugin(jsonSelect);
schema.set('toJSON', {select: 'name'});
Specifies fields when calling toJSON.
// this overrides a default configuration
JSON.stringify(doc.toJSON({select: 'name email'}));
The syntax for fields is the same with mongoose's Query#select.
http://mongoosejs.com/docs/api.html#query_Query-select
This plugin is proudly supported by Kubide desarrollo@kubide.es
MIT
FAQs
A mongoose plugin to limit JSON properties and set this properties to null.
The npm package k-mongoose-json-select receives a total of 2 weekly downloads. As such, k-mongoose-json-select popularity was classified as not popular.
We found that k-mongoose-json-select demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket now supports Scala and Kotlin, bringing AI-powered threat detection to JVM projects with easy manifest generation and fast, accurate scans.
Application Security
/Security News
Socket CEO Feross Aboukhadijeh and a16z partner Joel de la Garza discuss vibe coding, AI-driven software development, and how the rise of LLMs, despite their risks, still points toward a more secure and innovative future.
Research
/Security News
Threat actors hijacked Toptal’s GitHub org, publishing npm packages with malicious payloads that steal tokens and attempt to wipe victim systems.