【发布时间】:2017-02-27 03:39:38
【问题描述】:
我正在尝试为 mongoose 对象编写自定义验证器。这个想法是name 字段必须是不同集合中预先存在的对象的名称值。我这样做是这样的:
var seshSchema = new Schema(
{
student:
{
type: String,
validate: [
function(input)
{
studentColl.find({name: input},function(err, result){
if(err)
{
throw err;
}
return result.length > 0; //how do I make this get returned by the function in vaildate's array?
});
}, "nope"]
},
tutor: {type: String},
blockTimes: [blockTime],
record : [pastSession]
}
);
我要做的是根据不同集合 (studentColl) 中是否存在某些标准来验证这篇文章。这可能吗?
【问题讨论】:
标签: node.js mongodb asynchronous mongoose schema