Reputation: 91
I have defined a schema for a meteor mongo collection using smpl-schema to validate and clean object.
import SimpleSchema from 'simpl-schema';
const schema = new SimpleSchema({
name:String,
age:Number,
address:{
type:String,
optional:True
}
}, {
clean: true,
});
data :
let doc = {
name:' ',
age:10,
}
Here my function to validate :
function validateData(doc){
let validationContext = schema.newContext();
validationContext.validate(doc);
if (!validationContext.isValid()) throw JSON.stringify(validationContext.validationErrors())
return true
}
It's error, it's output : Error: Cannot convert undefined or null to object [ValidateDataError]
Upvotes: 0
Views: 561
Reputation: 1
You have a typo in your schema, optional
should be set to true
import SimpleSchema from 'simpl-schema';
const schema = new SimpleSchema({
name:String,
age:Number,
address:{
type:String,
optional:true
}
}, {
clean: true,
});
Upvotes: 0