对于数组即
productDetails: [
{
commodityID: {
type: mongoose.Schema.Types.ObjectId,
required: true,
ref: "commodity",
},
perOnePrice: { type: String, required: true },
totalAmount: { type: Number, required: true },
},
],
使用
[
body('productDetails.*.commodityID').not().isEmpty()
body('productDetails.*.perOnePrice').not().isEmpty()
body('productDetails.*.totalAmount').not().isEmpty()
]
对于嵌套对象,假设:
productDetails: {
commodityID: {
type: mongoose.Schema.Types.ObjectId,
required: true,
ref: "commodity",
},
perOnePrice: { type: String, required: true },
totalAmount: { type: Number, required: true },
},
使用
[
body('productDetails.commodityID').not().isEmpty()
body('productDetails.perOnePrice').not().isEmpty()
body('productDetails.totalAmount').not().isEmpty()
]