mongoose-throw-unselected
Throws an error whenever you access a field on a mongoose document that is not selected
Usage
const mongooseThrowUnselected = ;
examples
It throws an error if accessing a field that is not included in the projection
If you explicitly exclude a field (like via .select()
on a query) and you access that
field, this plugin will throw an error. This plugin adds a custom setter on each field that checks
if the field is included by checking isSelected()
.
const schema = name: first: String last: String age: Number; schema; const Model = mongoose; return Model // Explicitly exclude 'name.first' ;