Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mongoose Boolean validation not working if a String is provided #4245

Closed
andresgariglio opened this issue Jun 16, 2016 · 1 comment
Closed
Labels
backwards-breaking enhancement This issue is a user-facing general improvement that doesn't fix a bug or add a new feature
Milestone

Comments

@andresgariglio
Copy link

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.

@vkarpov15 vkarpov15 added this to the 4.5.2 milestone Jun 17, 2016
@vkarpov15 vkarpov15 added the bug? label Jun 17, 2016
@vkarpov15 vkarpov15 modified the milestones: 4.5.4, 4.5.3 Jun 25, 2016
@vkarpov15
Copy link
Collaborator

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.

@vkarpov15 vkarpov15 added enhancement This issue is a user-facing general improvement that doesn't fix a bug or add a new feature backwards-breaking and removed bug? labels Jul 11, 2016
@vkarpov15 vkarpov15 modified the milestones: 5.0, 4.5.4 Jul 11, 2016
@vkarpov15 vkarpov15 modified the milestones: Parking Lot, 5.0 Nov 24, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backwards-breaking enhancement This issue is a user-facing general improvement that doesn't fix a bug or add a new feature
Projects
None yet
Development

No branches or pull requests

3 participants