填充似乎没有填充所有数组元素 [英] Populate does not seem to populate for all the array elements
问题描述
考虑下面的代码:
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"
}
});
这是输出:
问题:只填充第一个孩子.我已经仔细检查了数据库,它不是空的.
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?
推荐答案
尝试将 perDocumentLimit
添加到您的填充选项中:https://mongoosejs.com/docs/api/model.html#model_Model.填充
Try adding perDocumentLimit
to your populate options:
https://mongoosejs.com/docs/api/model.html#model_Model.populate
由于遗留原因,使用 populate() 进行限制可能会给出不正确的结果,因为它只对每个被填充的文档执行一个查询.如果您设置 perDocumentLimit,Mongoose 将通过对每个要填充的文档执行单独的查询来确保每个文档的正确限制.
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().
这篇关于填充似乎没有填充所有数组元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!