MongoDB 聚合 $group
聚合 $group
此聚合阶段根据提供的唯一 _id
表达式对文档进行分组。
不要将此 _id
表达式与为每个文档提供的 _id
ObjectId 混淆。
示例
In this example, we are using the "sample_airbnb" database loaded from our sample data in the Intro to Aggregations section. (在此示例中,我们使用的是在“聚合入门”部分的示例数据中加载的“sample_airbnb”数据库。)
db.listingsAndReviews.aggregate(
[ { $group : { _id : "$property_type" } } ]
)
自己动手试一试 »
这将返回 property_type
字段的唯一值。