简单模式在必填字段中接受空值
Simple schema is accepting null values in required fields
Simple Schema 正在接受 null
并将其插入必填字段。不应该报错吗?有人可以指出我在这里做错了什么吗?
我正在使用这些软件包。
- mdg:验证方法
- mdg:验证错误
- 简单模式
Simple Schema
export const ProfileCandidate = new Mongo.Collection('profileCandidate');
const profileCandidate = new SimpleSchema({
name: Object,
'name.first': String,
'name.last': String,
}
});
Method Call
var data = {
'name.first': this.state.firstName,
'name.last': this.state.lastName,
};
insertProfileCandidate.call(data, (err, res) => {
if(err) {
console.log("err: ", err);
}
});
ValidateMethod
export const insertProfileCandidate = new ValidatedMethod({
name: 'profileCandidate.insert',
validate: new SimpleSchema({
'name.first': { type: String, min: 1 },
'name.last': { type: String, min: 1 },
}).validator({ clean: true }),
run(data) {
ProfileCandidate.insert({
name: {
first: data['name.first'],
last: data['name.last'],
}
}, (error, result) => {
if (error) throw new Meteor.Error('400', error.invalidKeys);
});
}
});
好的,看来我还需要安装 collection2-core
Simple Schema 正在接受 null
并将其插入必填字段。不应该报错吗?有人可以指出我在这里做错了什么吗?
我正在使用这些软件包。
- mdg:验证方法
- mdg:验证错误
- 简单模式
Simple Schema
export const ProfileCandidate = new Mongo.Collection('profileCandidate');
const profileCandidate = new SimpleSchema({
name: Object,
'name.first': String,
'name.last': String,
}
});
Method Call
var data = {
'name.first': this.state.firstName,
'name.last': this.state.lastName,
};
insertProfileCandidate.call(data, (err, res) => {
if(err) {
console.log("err: ", err);
}
});
ValidateMethod
export const insertProfileCandidate = new ValidatedMethod({
name: 'profileCandidate.insert',
validate: new SimpleSchema({
'name.first': { type: String, min: 1 },
'name.last': { type: String, min: 1 },
}).validator({ clean: true }),
run(data) {
ProfileCandidate.insert({
name: {
first: data['name.first'],
last: data['name.last'],
}
}, (error, result) => {
if (error) throw new Meteor.Error('400', error.invalidKeys);
});
}
});
好的,看来我还需要安装 collection2-core