简体   繁体   English

如何在 ZCCADCDEDB567ABAE643E15DCF0974E503Z 架构的 object 中声明动态密钥

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

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.我如何在 mongoose 模式中声明上述内容,因为 object 的键值是可变的。 Can i just use alerts: [Object] or alerts: [Schema.Types.Mixed] and use all kinds of objects within?我可以只使用 alerts alerts: [Object]alerts: [Schema.Types.Mixed]并在其中使用各种对象吗? or is there a better solution.还是有更好的解决方案。

Thanks in advance!提前致谢!

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:您可以将路径声明为Mixed类型,方法是将其声明为以下之一:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM