猫鼬架构限制

时间:2020-10-16 16:28:07

标签: mongodb mongoose schema

在下面的示例中,如何根据 id 属性是什么,有条件地为 amount 设置min属性?

如果 id 为1,则金额的最小值为10,否则为5

const item = new mongoose.Schema({
  id: {
    type: Number,
    required: true
  },

  amount: {
    type: Number,
    min: ?,
    max: 100
  }
})

0 个答案:

没有答案