【发布时间】:2021-10-10 19:21:42
【问题描述】:
我正在检索以下数据:
[
{
"_id": null,
"count": 2,
"students": [
[
"a",
"b"
],
[
"a",
"c",
"d"
]
]
}
]
使用这个查询:
aggregate([
{
$match: {
class: {
$in: classes,
},
},
},
{
$project: { students: 1 },
},
{
$group: {
_id: null,
count: { $sum: 1 },
data: { $push: "$students" },
},
},
{
$project: {
count: 1,
students: {
$setIntersection: "$data",
},
},
},
])
但这个想法是,学生们成为这些数组的交叉点,以便只得到
[
{
"_id": null,
"count": 2,
"students": [
[
"a",
],
]
}
]
我尝试了几种使用 setIntersection 的组合,但都没有奏效。
怎么才能只有那个路口?
谢谢。
【问题讨论】:
标签: node.js mongodb mongoose aggregation-framework