【发布时间】:2020-11-27 07:57:54
【问题描述】:
我有以下有效的 mongo db 查询:
.collection('commentsPosts')
.aggregate(
[
{$match:{
commentedAt: {
$lte: from,
},
...(postId && { postId }),
}
},
{$lookup:
{
from:"users",
localField:"commentedBy",
foreignField:"_id",
as:"commenterDetails"
// NEED TO LOOK UP "posts" collection here to find number of posts by commenterDetails.userId = posterId in posts table
},
}
]
)
我需要再往下一层来查找帖子数量,以查找帖子集合中commenterDetails.userId = posterId 的帖子数量
我正在寻找一种方法将下面的工作查询添加到上面的查询中。
const userPostCount = await req.db.collection('posts').countDocuments({
creatorId: userId,
});
【问题讨论】:
标签: mongodb mongoose mongodb-query