【发布时间】:2020-03-23 05:34:20
【问题描述】:
我的查询如下所示:
const articles = await Article.find(query)
.populate({
path: 'votedUsers', // array of users id
select: 'title name username',
options: {
limit: 3,
sort: { createdAt: -1 },
},
})
.exec()
结果:
[
{
title: 'Article title',
votedUsers: [,,], // array of populated users with limit of 3
totalCountVoted: 200 // need to add this field
}
]
我想查找文章并填充 votedUsers 属性,但限制为 3 个用户,但同时
我需要知道votedUsers 属性中有多少个 id。
例如,可能有 200 个用户对那篇文章进行了投票,但我只需要知道这个数字并只填充其中的 3 个。
【问题讨论】: