How do i declare a dynamic key in an object for a Mongoose Schema

Viewed 678

I have a structure like this

alerts: {
[symbol: string]: [
    {
     alert_price: number,
     price_when_set: number,
    }
  ]
},

how do i declare the above in a mongoose schema as the key value for the object is variable. Can i just use alerts: [Object] or alerts: [Schema.Types.Mixed] and use all kinds of objects within? or is there a better solution.

Thanks in advance!

1 Answers

Well after a lot of testing, I figured that that was indeed the solution. You can just declare the path as a Mixed type by either declaring it as on of the following:

  1. Schema.Types.Mixed
  2. Object
  3. Mongoose.Mixed
  4. {}
Related