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
欄位的唯一值。