【问题标题】:Mongoose populate subdocument in arrayMongoose 在数组中填充子文档
【发布时间】:2020-12-18 19:48:42
【问题描述】:

我有一个 Mongoose 报价模型,解释如下:

const OfferSchema = new Schema({
  sections: [
    {
      title: String,
    },
  ],
});

以及参考第一个模式报价的订单模式如下所述:

const OrderSchema = new Schema({
  offers: [
    {
      offer: { type: Schema.Types.ObjectId, ref: 'Offer' },
      sections: [
        {
          section: { type: Schema.Types.ObjectId, ref: 'Offer.sections' }, // issue here
        },
      ],
    },
  ],
});

我无法在此处填充部分的问题{section: { type: Schema.Types.ObjectId, ref: 'Offer.sections' }}

它给了我MissingSchemaError: Schema hasn't been registered for model "Offer.sections".

那么有什么方法可以填充部分吗?

【问题讨论】:

    标签: javascript node.js mongodb mongoose populate


    【解决方案1】:

    很遗憾,Mongoose 不支持此功能。 查看 Github 问题here

    您可以将部分嵌入到订单架构中的替代解决方案

    【讨论】:

      猜你喜欢
      • 2017-03-21
      • 2017-06-06
      • 2018-08-16
      • 2017-01-27
      • 1970-01-01
      • 2014-08-16
      • 2017-09-25
      • 2020-11-21
      • 2015-08-08
      相关资源
      最近更新 更多