【问题标题】:Is it possible to populate a reference to a sub-document array objectid on another model是否可以在另一个模型上填充对子文档数组 objectid 的引用
【发布时间】:2017-01-04 15:37:30
【问题描述】:

SampleModel:

{
    "Name": String,
    "brandid": {
        type: Schema.ObjectId,
        ref: 'BrandList.BrandItems',
    }
}

品牌型号:

{
    "BrandName" : String,
    "BrandItems": [{
        "KG": Number,
        "_id" : {type: Schema.ObjectId}
    }]
}

如何将子文档数组的 ObjectId 引用到另一个模型,以及如何将 populate() 用于此“brandid”?

【问题讨论】:

    标签: mongodb mongoose mongodb-query


    【解决方案1】:

    Mongodb 没有外键。您必须在应用程序代码中执行此操作。

    【讨论】:

      猜你喜欢
      • 2018-06-07
      • 2021-04-24
      • 2019-01-26
      • 2016-05-09
      • 2015-06-04
      • 2015-07-28
      • 2015-10-31
      • 2020-08-15
      • 2016-04-13
      相关资源
      最近更新 更多