简体   繁体   English

Mongoose 在数组中填充子文档

[英]Mongoose populate subdocument in array

I have a Mongoose offer model explained below:我有一个猫鼬报价模型解释如下:

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

and order schema which has reference to to the first schema offer explained below:和 order 架构参考下面解释的第一个架构报价:

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

the problem that I can not populate sections here {section: { type: Schema.Types.ObjectId, ref: 'Offer.sections' }}我无法在此处填充部分的问题{section: { type: Schema.Types.ObjectId, ref: 'Offer.sections' }}

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

so is there any way to populate sections?那么有没有办法填充部分?

Unfortunately, Mongoose doesn't support this feature.不幸的是,Mongoose 不支持此功能。 check the Github issue here此处检查 Github 问题

The alternative solution you can embed sections into the order schema您可以将部分嵌入订单模式的替代解决方案

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

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