Populate does not seem to populate for all the array elements

心不动则不痛 提交于 2021-02-11 13:54:54

问题


Consider the code below:

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"
      }
    });

This is the output:

The problem: just the first children is populated. I have double-checked the database, and it is not empty.

I feel that I have seen this problem, but I cannot remember where. Could anyone refresh my memory?


回答1:


Try adding perDocumentLimit to your populate options: https://mongoosejs.com/docs/api/model.html#model_Model.populate

For legacy reasons, limit with populate() may give incorrect results because it only executes a single query for every document being populated. If you set perDocumentLimit, Mongoose will ensure correct limit per document by executing a separate query for each document to populate().



来源:https://stackoverflow.com/questions/60997183/populate-does-not-seem-to-populate-for-all-the-array-elements

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!