簡體   English   中英

Mongoose 在數組中填充子文檔

[英]Mongoose populate subdocument in array

我有一個貓鼬報價模型解釋如下:

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

和 order 架構參考下面解釋的第一個架構報價:

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

那么有沒有辦法填充部分?

不幸的是,Mongoose 不支持此功能。 此處檢查 Github 問題

您可以將部分嵌入訂單模式的替代解決方案

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM