path «String» options «Object» Boolean SchemaType constructor.
fn «Function» Override the function the required validator uses to check whether a boolean passes the required check.
Configure which values get casted to false.
const M = mongoose.model('Test', new Schema({ b: Boolean }));
new M({ b: 'nay' }).b; // undefined
mongoose.Schema.Types.Boolean.convertToFalse.add('nay');
new M({ b: 'nay' }).b; // false
Configure which values get casted to true.
const M = mongoose.model('Test', new Schema({ b: Boolean }));
new M({ b: 'affirmative' }).b; // undefined
mongoose.Schema.Boolean.convertToTrue.add('affirmative');
new M({ b: 'affirmative' }).b; // true
getter «Function» Attaches a getter for all Boolean instances
mongoose.Schema.Boolean.get(v => v === true ? 'yes' : 'no');
const Order = mongoose.model('Order', new Schema({ isPaid: Boolean }));
new Order({ isPaid: false }).isPaid; // 'no'
caster «Function» Get/set the function used to cast arbitrary values to booleans.
// Make Mongoose cast empty string '' to false.
const original = mongoose.Schema.Boolean.cast();
mongoose.Schema.Boolean.cast(v => {
if (v === '') {
return false;
}
return original(v);
});
// Or disable casting entirely
mongoose.Schema.Boolean.cast(false);
value «Any» Check if the given value satisfies a required validator. For a boolean to satisfy a required validator, it must be strictly equal to true or to false.
This schema type's name, to defend against minifiers that mangle function names.
option «String» The option you'd like to set the value for value «Any» value for option Sets a default option for all Boolean instances.
// Make all booleans have `default` of false.
mongoose.Schema.Boolean.set('default', false);
const Order = mongoose.model('Order', new Schema({ isPaid: Boolean }));
new Order({ }).isPaid; // false
© 2010 LearnBoost
Licensed under the MIT License.
https://mongoosejs.com/docs/api/schemaboolean.html