Home > Mobile >  Mongoose leaves creates an empty array
Mongoose leaves creates an empty array

Time:01-06

Inserted Object

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
}

with this Schema:

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})

When I review the DB saves everything fine except for bookingDates, it leaves an empty array.

I tried this enter link description here unsuccessfully.

I doing something wrong but I don't know what, any idea?

Thanks

CodePudding user response:

You need to set type and default properties for bookindDates,

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

CodePudding user response:

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

This is how ended up working, but also the main problem was the property name in the Schema was misspelled bookindDates instead bookingDates.

  • Related