给定 MongoDB 中的以下数据:
[
{ id: 1, stuff: ["A", "B"] },
{ id: 2, stuff: ["B", "C"] },
... (lots and lots of records)
]
是否有可能获得所有“东西”集的联合?例如["A","B","C"]
我试过使用$addToSet
aggregate([
{ $group: {
_id: null,
allStuff: { $addToSet: "$stuff" }
}
}
])
但这会创建一组集合,例如[ ["A", "B"], ["B", "C"] ]