我想在我的应用中实施评论部分,我想限制每条评论。限制应该是每个注释的字符长度不小于3且不长于150.这是我的架构:
const ComentsSchema = new Schema({
comments: [{
comment: { type: String , validate: checkComment},
commentator: { type: String }
}]
});
现在验证部分出了问题。当我摆脱它,应用程序工作和评论保存在数据库中,但我没有限制。我究竟做错了什么?这是我的验证代码:
let checkComment = (comment) => {
if (!comment[0]) {
return false;
} else if (comment[0].length < 3 || comment[0].length > 150) {
return false;
} else {
return true;
}
};