猫鼬填充数组中的子文档

时间:2020-08-30 13:53:30

标签: javascript node.js mongodb mongoose populate

我有以下解释的猫鼬报价模型:

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".

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

1 个答案:

答案 0 :(得分:1)

不幸的是,猫鼬不支持此功能。 检查Github问题here

您可以将部分嵌入订单模式的替代解决方案