Mongoose leaves创建一个空数组

gajydyqb  于 2023-01-05  发布在  Go
关注(0)|答案(1)|浏览(99)

我有这个东西

newSale {
  productCode: 'MRS-GT-EN',
  amount: 359.89,
  serial: 4143,
  orderNumber: 2241,
  bookingDates: [
    { date: '9-1-2023', time: 6 },
    { date: '10-1-2023', time: 6 },
    { date: '11-1-2023', time: 6 },
    { date: '12-1-2023', time: 6 },
    { date: '13-1-2023', time: 6 },
    { date: '14-1-2023', time: 6 },
    { date: '15-1-2023', time: 6 },
    { date: '16-1-2023', time: 6 }
  ],
  delivered: false
}

使用此架构:

const saleSchema = new Schema({
    productCode: { type: String, required: true },
    amount: { type: Number, required: true },
    serial: { type: Number, required: true },
    orderNumber: { type: Number, required: true},
    bookindDates: [{date: {type: String}, time:{type:Number}}],
    delivered: { type: Boolean, required: true }
}, { timestamps: true})

当我检查DB时,除了bookingDates之外,它保存了所有内容,但留下了一个空数组。
我尝试了这个enter link description here,但没有成功。
我做错了什么,但我不知道是什么,你知道吗?
谢啦,谢啦

p1tboqfb

p1tboqfb1#

您需要为bookindDates设置typedefault属性,

bookindDates: {
  type: [{ date: String, time: Number }]
  default: undefined
}

相关问题