【问题标题】:Invalid schema configuration: [OBject Object] is not a valid type within the array无效的架构配置:[OBject Object] 不是数组中的有效类型
【发布时间】:2019-08-16 18:29:31
【问题描述】:

我在 mongoose 上的架构遇到了一些错误。

我的架构如下:

{
accomodations : {
        rooms : {
            type : [{
                rooms : [{
                    type : {
                        id : { type : Number },
                        name : {
                            ita : { type : String },
                            eng : { type : String },
                        },
                        numberOfRooms : { type : Number },
                    },
                }],
                boards : [{
                    id : { type : String },
                    type : {
                        id : { type : Number },
                        name : {
                            ita : { type : String },
                            eng : { type : String },
                        },
                    },
                    amount : {
                        currency : { type : String },
                        directPayment : { type : Boolean },
                        totalPrice : { type : Number },
                        mandatory : { type : Boolean },
                        priceAgency : { type : Number },
                        refundable : { type : Boolean },
                        markupPrice : { type : Number },
                    },
                }],
                amenities : [{ type : mongoose.Schema.Types.Mixed }],
            }],
        },
    }
}

如果我使用“类型”作为属性名称,我会收到一个错误: 架构配置无效:[object Object] 不是数组 rooms 中的有效类型。有关有效架构类型的列表,请参见 http://bit.ly/mongoose-schematypes。

我需要在我的架构中有一个名为 type 的属性。

【问题讨论】:

    标签: node.js mongoose schema


    【解决方案1】:

    你永远不应该有一个名为 type 的字段。这是许多语言中的保留字,会引起很多麻烦。不确定您使用的是什么语言,我建议您尝试重命名为“roomType”

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-07-23
      • 2020-03-26
      • 1970-01-01
      • 2021-03-24
      • 2016-11-30
      • 1970-01-01
      • 2022-01-04
      • 1970-01-01
      相关资源
      最近更新 更多