基于其他字段值的猫鼬动态模式类型

时间:2021-03-23 08:06:09

标签: javascript mongodb typescript validation mongoose

假设我有以下架构:

new Schema({
  fruitType: {
    type: String,
    enum: ['apple', 'orange', 'melon', 'mango'],
    required: true,
  },
  fruitValue: [ appleSchema ],
})

fruitType 为 apple 时,我希望 fruitValueappleSchema,当它为 melon 时,我希望该字段具有 melonSchema。 Mongoose 有没有办法做到这一点?

0 个答案:

没有答案