【发布时间】:2020-09-07 20:02:13
【问题描述】:
{
$lookup: {
from: "Comment",
let: {
p_id: "$_id",
d_id: "$data_id",
},
pipeline: [
{
$match: {
$expr: {
$and: [
{
$eq: [
"$_id",
"$$p_id"
]
},
{
$eq: [
"$data_id",
"$$d_id"
]
}
]
}
}
}
],
as: "subComment"
}
}
https://mongoplayground.net/p/GbEgnVn3JSv 我擅长 mongoplayground,但试图把我的想法放在那里
我想获取基于 doc_id 和 post_id 的帖子评论,用于 mainComment 查询看起来不错,但子命令不好。请指导一下
它很简单,因为一个帖子可以有多个评论,需要评论计数基于 Post.data._id 等于 Comment.doc_id 和 Post._id 在 Comment.post_id 中
【问题讨论】:
标签: node.js mongodb aggregation-framework aggregate-functions