【问题标题】:Populate does not seem to populate for all the array elements填充似乎没有填充所有数组元素
【发布时间】:2020-07-14 18:07:21
【问题描述】:

考虑下面的代码:

const aux = await Fasta.find({}, "healthyTissue")
    .limit(1)
    .populate({
      //---------------------first level (healthy or tumor fasta file) ----------------
      path: "healthyTissue",
      model: "Hidden",

      options: {
        limit: 2
      },

      //---------------------    second level (hidden documents)       ----------------
      populate: {
        path: "children",
        options: {
          limit: 2
        },
        model: "FastaElement"
      }
    });

这是输出:

问题:只填充了第一个孩子。我仔细检查了数据库,它不是空的

我觉得我看到过这个问题,但我不记得在哪里。 谁能刷新我的记忆?

【问题讨论】:

    标签: mongoose mongoose-populate


    【解决方案1】:

    尝试将perDocumentLimit 添加到您的填充选项中: https://mongoosejs.com/docs/api/model.html#model_Model.populate

    由于遗留原因,使用 populate() 进行限制可能会给出不正确的结果,因为它只对每个正在填充的文档执行一个查询。如果您设置 perDocumentLimit,Mongoose 将通过对要填充()的每个文档执行单独的查询来确保每个文档的限制正确。

    【讨论】:

    • 谢谢,我从零开始编程。我记得我以某种方式看到了这个问题,但是,我不记得在哪里。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-13
    • 1970-01-01
    • 2016-05-24
    • 1970-01-01
    • 2021-02-03
    • 1970-01-01
    相关资源
    最近更新 更多