我有以下架构:
var Schema = new mongoose.Schema({});
Schema.add({
type: {
type: String
, enum: ['one', 'two', 'three']
}
});
Schema.add({
title: {
type: String
//, required: true ned set by some conditional
}
});
正如您可以从预置模式定义中看到的那样,我有两个字段type和title. 第二个 ( title) 必须是required: trueonly if typeis(one | two)并且必须是falseif type is three。
我怎么能用猫鼬做呢?
编辑:感谢您的回答。我还有一个相关的问题要在这里问:
如果不需要,我可以删除字段吗?假设类型 ifthree但也提供了title字段。为了防止存储不必要title的在这种情况下如何删除它?