【问题标题】:Populating Array of arrays containing ref in Mongoose在 Mongoose 中填充包含 ref 的数组数组
【发布时间】:2019-01-23 23:57:58
【问题描述】:

我的架构中有一个包含 ref 的数组数组。我想填充内部数组,其中 _ids 数组内部对 我的架构如下所示:

var lunchBuddySchema = new mongoose.Schema({
    title: String,
    pairs: [[{         
        type: mongoose.Schema.Types.ObjectId,
        ref: "User"
    }]],
});

我想填充“对”。当我将 ID 推送到对数组中时,我得到如下信息:

"pairs": [
    [
      "5b7484deff813ab2c0aa9a32",
      "5b74b49133027fba2c959379"
    ],
    [
      "5b75cab4e5953acb5e44d044",
      "5b75ca14e5953acb5e44d03f"
    ],
    [
      "5b65374a13c29342ae56d098",
      "5b73ba56bae5d9a21305993f"
    ],
    [
      "5b75ca48e5953acb5e44d041",
      "5b75ca6de5953acb5e44d042"
    ]
  ],
  "_id": "5b75f9a2040d9dd5e3f60979",
  "title": "Week 2",
  "__v": 0
}

大多数时候我在填充时使用exec.populate('pairs'),但在这种情况下它不起作用。

【问题讨论】:

    标签: arrays mongodb mongoose mongoose-schema mongoose-populate


    【解决方案1】:

    试试这个

    填充({ 路径:'对', 填充:{路径:'对'} });

    【讨论】:

      猜你喜欢
      • 2013-05-14
      • 2020-11-03
      • 1970-01-01
      • 2019-07-28
      • 2019-03-28
      • 2014-12-05
      • 2019-01-31
      • 1970-01-01
      相关资源
      最近更新 更多