我想在每一条动态下面显示对应的评论个数。
在云函数中,尝试了将动态列表查询出来之后使用map来将每一条动态的评论数commentCount加进去。
let dynamicList = await db.collection("dynamicList").where({
"cid": event.cid
}).orderBy("date", "desc").get().then(res => {
return res.data
})
return dynamicList.map(async (element) => {
let did = element.did
let commentCount = await db.collection("comment").where({
"did": did
}).count().then(res => {
return res.total
})
return {
...element,
'commentCount': commentCount
}
})
但是返回的结果是
麻烦大佬指点一下。
聚合查询然后统计,可以参考我写的排行版统计
https://developers.weixin.qq.com/community/develop/article/doc/00044e209a41f800b9caa638451c13