Given the following schema with a Boolean field:
var UserSchema = new Schema({
_id: {
type: Number
},
enabled: {
type: Boolean,
default: false
}
});
When trying to save a document, if I supply a random string instead of a Boolean value or "Boolean string" (e.g. "false" or "true" instead of just false/true) for enabled field, the document is still being saved properly, with the Boolean field set to true.
Expected behavior: save operation should throw a ValidationError.
Yeah unfortunately this is backwards breaking, mongoose will cast anything into a boolean and this is expected behavior. Will make this change for the next major release.
Most helpful comment
Yeah unfortunately this is backwards breaking, mongoose will cast anything into a boolean and this is expected behavior. Will make this change for the next major release.