Open elad opened 9 years ago
You need to manually add validators:
var Person = db.define('person', {
name: String
}, {
validations: {
name: function (data, next, thisArg, contexts) {
if (typeof data != 'string') {
return next(new Error("%s is not a valid type for the field 'name'!", typeof data));
}
next();
}
}
});
Hello,
Here's some code:
I expected to see
validate
andsave
both fail, but that's not the case. After running this code, my MongoDB database has a new object with an Integer field forname
with the value 1234.Is this a bug? If not, is there a built-in way for enforcing types?
Thanks!